Commit b3a28b6b authored by Pietro Abate's avatar Pietro Abate

[r2003-05-26 20:36:58 by cvscast] toplevel et commentaire pour faire plaisir eppe ;-)

Original author: cvscast
Date: 2003-05-26 20:36:58+00:00
parent e116f3cc
......@@ -77,7 +77,8 @@ let toploop () =
Cduce.toplevel := true;
Location.push_source `Stream;
let read i =
if !bol then outflush "> ";
if !bol then
if !Wlexer.in_comment then outflush "* " else outflush "> ";
try
let c = input_char stdin in
bol := c = '\n';
......
......@@ -76,6 +76,8 @@ let nb_classes = 40
let keywords = Hashtbl.create 17
let in_comment = ref false
let error = Location.raise_loc
exception Illegal_character of char
exception Unterminated_comment
......@@ -203,10 +205,10 @@ let lex_tables = {
let rec token engine lexbuf =
match engine lex_tables 0 lexbuf with
0 -> (
# 88 "parser/wlexer.mll"
# 90 "parser/wlexer.mll"
token engine lexbuf )
| 1 -> (
# 90 "parser/wlexer.mll"
# 92 "parser/wlexer.mll"
let s = Lexing.lexeme lexbuf in
if (s.[0] >= 'A') && (s.[0] <= 'Z')
......@@ -214,16 +216,16 @@ let rec token engine lexbuf =
else if Hashtbl.mem keywords s then "",s else "LIDENT",s
)
| 2 -> (
# 97 "parser/wlexer.mll"
# 99 "parser/wlexer.mll"
"INT",Lexing.lexeme lexbuf )
| 3 -> (
# 102 "parser/wlexer.mll"
# 104 "parser/wlexer.mll"
"",Lexing.lexeme lexbuf )
| 4 -> (
# 103 "parser/wlexer.mll"
# 105 "parser/wlexer.mll"
"DIRECTIVE",Lexing.lexeme lexbuf )
| 5 -> (
# 105 "parser/wlexer.mll"
# 107 "parser/wlexer.mll"
let string_start = Lexing.lexeme_start lexbuf in
string_start_pos := string_start;
let double_quote = Lexing.lexeme_char lexbuf 0 = '"' in
......@@ -233,15 +235,17 @@ let rec token engine lexbuf =
(if double_quote then "STRING2" else "STRING1"),
(get_stored_string()) )
| 6 -> (
# 115 "parser/wlexer.mll"
# 117 "parser/wlexer.mll"
comment_start_pos := [Lexing.lexeme_start lexbuf];
in_comment := true;
comment engine lexbuf;
in_comment := false;
token engine lexbuf )
| 7 -> (
# 120 "parser/wlexer.mll"
# 124 "parser/wlexer.mll"
"EOI","" )
| 8 -> (
# 122 "parser/wlexer.mll"
# 126 "parser/wlexer.mll"
error
(Lexing.lexeme_start lexbuf) (Lexing.lexeme_end lexbuf)
(Illegal_character ((Lexing.lexeme lexbuf).[0])) )
......@@ -250,17 +254,17 @@ let rec token engine lexbuf =
and comment engine lexbuf =
match engine lex_tables 1 lexbuf with
0 -> (
# 128 "parser/wlexer.mll"
# 132 "parser/wlexer.mll"
comment_start_pos := Lexing.lexeme_start lexbuf :: !comment_start_pos;
comment engine lexbuf;
)
| 1 -> (
# 132 "parser/wlexer.mll"
# 136 "parser/wlexer.mll"
comment_start_pos := List.tl !comment_start_pos;
if !comment_start_pos <> [] then comment engine lexbuf;
)
| 2 -> (
# 136 "parser/wlexer.mll"
# 140 "parser/wlexer.mll"
string_start_pos := Lexing.lexeme_start lexbuf;
Buffer.clear string_buff;
let ender = Lexing.lexeme lexbuf in
......@@ -271,51 +275,51 @@ and comment engine lexbuf =
Buffer.clear string_buff;
comment engine lexbuf )
| 3 -> (
# 146 "parser/wlexer.mll"
# 150 "parser/wlexer.mll"
let st = List.hd !comment_start_pos in
error st (st+2) Unterminated_comment
)
| 4 -> (
# 150 "parser/wlexer.mll"
# 154 "parser/wlexer.mll"
comment engine lexbuf )
| _ -> failwith "lexing: empty token [comment]"
and string ender engine lexbuf =
match engine lex_tables 2 lexbuf with
0 -> (
# 154 "parser/wlexer.mll"
# 158 "parser/wlexer.mll"
let c = Lexing.lexeme lexbuf in
if c = ender then ()
else (store_len lexbuf;
store_char (Lexing.lexeme lexbuf);
string ender engine lexbuf) )
| 1 -> (
# 160 "parser/wlexer.mll"
# 164 "parser/wlexer.mll"
store_len lexbuf;
store_ascii (Lexing.lexeme_char lexbuf 1);
string ender engine lexbuf )
| 2 -> (
# 164 "parser/wlexer.mll"
# 168 "parser/wlexer.mll"
let c = Lexing.lexeme_char lexbuf 1 in
if c = 'x'
then parse_hexa_char engine lexbuf
else (store_len lexbuf; store_special c);
string ender engine lexbuf )
| 3 -> (
# 170 "parser/wlexer.mll"
# 174 "parser/wlexer.mll"
store_len lexbuf;
store_code (numeric_char (Lexing.lexeme lexbuf));
string ender engine lexbuf )
| 4 -> (
# 174 "parser/wlexer.mll"
# 178 "parser/wlexer.mll"
error
(Lexing.lexeme_start lexbuf) (Lexing.lexeme_end lexbuf)
(Illegal_character '\\') )
| 5 -> (
# 178 "parser/wlexer.mll"
# 182 "parser/wlexer.mll"
error !string_start_pos (!string_start_pos+1) Unterminated_string )
| 6 -> (
# 180 "parser/wlexer.mll"
# 184 "parser/wlexer.mll"
store_len lexbuf;
store_code (Char.code (Lexing.lexeme_char lexbuf 0));
(* Adapt when source is UTF8 *)
......@@ -325,11 +329,11 @@ and string ender engine lexbuf =
and parse_hexa_char engine lexbuf =
match engine lex_tables 3 lexbuf with
0 -> (
# 187 "parser/wlexer.mll"
# 191 "parser/wlexer.mll"
store_len ~add:2 lexbuf;
store_code (hexa_char (Lexing.lexeme lexbuf)) )
| 1 -> (
# 190 "parser/wlexer.mll"
# 194 "parser/wlexer.mll"
error
(Lexing.lexeme_start lexbuf) (Lexing.lexeme_end lexbuf)
(Illegal_character '\\') )
......@@ -337,7 +341,7 @@ and parse_hexa_char engine lexbuf =
;;
# 196 "parser/wlexer.mll"
# 200 "parser/wlexer.mll"
let delta_loc = ref 0
......
......@@ -17,6 +17,8 @@ classes
{
let keywords = Hashtbl.create 17
let in_comment = ref false
let error = Location.raise_loc
exception Illegal_character of char
exception Unterminated_comment
......@@ -113,7 +115,9 @@ rule token = parse
| "(*"
{ comment_start_pos := [Lexing.lexeme_start lexbuf];
in_comment := true;
comment engine lexbuf;
in_comment := false;
token engine lexbuf }
| eof
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment