Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
5b00c5a8
Commit
5b00c5a8
authored
Oct 05, 2007
by
Pietro Abate
Browse files
[r2002-11-11 00:00:11 by cvscast] Empty log message
Original author: cvscast Date: 2002-11-11 00:00:48+00:00
parent
4f15f8b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
toplevel/toploop.ml
View file @
5b00c5a8
open
Printf
open
Parser
type
line_buffer
=
{
mutable
buffer
:
string
;
...
...
@@ -8,25 +8,20 @@ type line_buffer =
maxlength
:
int
;
}
(* Discard data left in lexer buffer. *)
let
empty_buf
buf
=
buf
.
length
<-
0
;
buf
.
abs_pos
<-
0
;
(* this function fills the line buffer printing
the prompt :-> at the first line *)
the prompt ?> at the first line and returning
the number of characters in the line '\n' included*)
let
first_line
=
ref
true
let
got_eof
=
ref
false
let
refill_buf
buffer
len
=
if
!
got_eof
then
(
got_eof
:=
false
;
0
)
else
begin
let
prompt
=
if
!
first_line
then
"
:-
> "
else
"
"
if
!
first_line
then
"
?
> "
else
" "
in
output_string
stdout
prompt
;
flush
stdout
;
first_line
:=
false
;
...
...
@@ -54,15 +49,19 @@ let refill_buf buffer len =
let
rec
scan
line_buf
count
=
let
element
=
count
-
(
line_buf
.
abs_pos
)
in
if
element
<
line_buf
.
length
-
1
then
(* send to stream the character *)
(*test: print_int count;print_char ':'; print_int line_buf.abs_pos;
print_char ':'; print_int element; print_char ' '; *)
if
element
<
line_buf
.
length
then
(* send to stream the character *)
Some
line_buf
.
buffer
.
[
element
]
else
(
(* read another line*)
line_buf
.
abs_pos
<-
(
line_buf
.
abs_pos
)
+
line_buf
.
length
;
line_buf
.
length
<-
refill_buf
line_buf
.
buffer
line_buf
.
maxlength
;
line_buf
.
length
<-
(
refill_buf
line_buf
.
buffer
line_buf
.
maxlength
)
-
1
;
scan
line_buf
count
)
(* JUST FOR TESTING *)
(* JUST FOR TESTING *)
let
loop
=
fprintf
stdout
" CDuce version 0.2a1
\n\n
"
;
let
line_buffer
=
...
...
@@ -72,21 +71,28 @@ let loop =
maxlength
=
60
;
}
in
let
input
=
Stream
.
from
(
scan
line_buffer
)
in
Sys
.
catch_break
true
;
Sys
.
catch_break
true
;
while
true
do
empty_buf
line_buffer
;
first_line
:=
true
;
let
double
semicolon
=
ref
false
in
let
semicolon
=
ref
false
in
while
not
!
doublesemicolon
do
let
c
=
Stream
.
next
input
in
if
c
=
'
;
'
then
(
if
!
semicolon
then
doublesemicolon
:=
true
else
semicolon
:=
true
)
else
semicolon
:=
false
;(
*
output_char
stdout
c
*
)
let
semicolon
=
ref
0
in
while
!
semicolon
<
2
do
let
c
=
Stream
.
next
input
in
if
c
=
'
;
'
then
incr
semicolon
else
semicolon
:=
0
done
done
(* JUST FOR TESTING 2
*)
(* JUST FOR TESTING 2
let loop =
fprintf stdout " CDuce version 0.2a1\n\n";
let line_buffer =
...
...
@@ -98,13 +104,11 @@ let loop =
let input = Stream.from (scan line_buffer) in
Sys.catch_break true;
while true do
empty_buf
line_buffer
;
first_line := true;
try
Parser
.
prog
input
with
|
Stdpp
.
Exc_located
(
loc
,
e
)
->
raise
(
Location
(
loc
,
e
))
try Parser.prog input ; () with _ -> ()
done
*)
(* THE REAL LOOP
...
...
@@ -144,5 +148,3 @@ let loop ppf =
*)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment