summaryrefslogtreecommitdiff
path: root/lex/lexer.mll
diff options
context:
space:
mode:
authorLuc Maranget <luc.maranget@inria.fr>2002-10-28 16:46:50 +0000
committerLuc Maranget <luc.maranget@inria.fr>2002-10-28 16:46:50 +0000
commitc417b82d9e0c2cd3d451ce1030502efed946d516 (patch)
tree1dc5ad1743ca1732c3157afbabc933b8f10744be /lex/lexer.mll
parent123036485b165a3ceb873211a1f73e7e523b68e1 (diff)
downloadocaml-c417b82d9e0c2cd3d451ce1030502efed946d516.tar.gz
nouveau ocamllex
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5193 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'lex/lexer.mll')
-rw-r--r--lex/lexer.mll38
1 files changed, 9 insertions, 29 deletions
diff --git a/lex/lexer.mll b/lex/lexer.mll
index d1b37f6014..6ab0380c4c 100644
--- a/lex/lexer.mll
+++ b/lex/lexer.mll
@@ -67,23 +67,8 @@ let handle_lexical_error fn lexbuf =
fn lexbuf
with Lexical_error(msg, _, _) ->
raise(Lexical_error(msg, line, column))
-
-let warning lexbuf msg =
- Printf.eprintf "ocamllex warning:\nFile \"%s\", line %d, character %d: %s.\n"
- Sys.argv.(1) !line_num
- (Lexing.lexeme_start lexbuf - !line_start_pos) msg;
- flush stderr;
-;;
-
}
-let identstart =
- ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255']
-let identbody =
- ['A'-'Z' 'a'-'z' '_' '\192'-'\214' '\216'-'\246' '\248'-'\255' '\'' '0'-'9']
-let backslash_escapes =
- ['\\' '"' '\'' 'n' 't' 'b' 'r']
-
rule main = parse
[' ' '\013' '\009' '\012' ] +
{ main lexbuf }
@@ -95,14 +80,15 @@ rule main = parse
{ comment_depth := 1;
handle_lexical_error comment lexbuf;
main lexbuf }
- | '_' { Tunderscore }
- | identstart identbody *
+ | ['A'-'Z' 'a'-'z'] ['A'-'Z' 'a'-'z' '\'' '_' '0'-'9'] *
{ match Lexing.lexeme lexbuf with
"rule" -> Trule
| "parse" -> Tparse
+ | "shortest" -> Tparse_shortest
| "and" -> Tand
| "eof" -> Teof
| "let" -> Tlet
+ | "as" -> Tas
| s -> Tident s }
| '"'
{ reset_string_buffer();
@@ -110,7 +96,7 @@ rule main = parse
Tstring(get_stored_string()) }
| "'" [^ '\\'] "'"
{ Tchar(Char.code(Lexing.lexeme_char lexbuf 1)) }
- | "'" '\\' backslash_escapes "'"
+ | "'" '\\' ['\\' '\'' 'n' 't' 'b' 'r'] "'"
{ Tchar(Char.code(char_for_backslash (Lexing.lexeme_char lexbuf 2))) }
| "'" '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
{ Tchar(Char.code(char_for_decimal_code lexbuf 2)) }
@@ -124,6 +110,7 @@ rule main = parse
start_line = l1; start_col = n1 - s1}) }
| '=' { Tequal }
| '|' { Tor }
+ | '_' { Tunderscore }
| '[' { Tlbracket }
| ']' { Trbracket }
| '*' { Tstar }
@@ -151,9 +138,9 @@ and action = parse
string lexbuf;
reset_string_buffer();
action lexbuf }
- | "'" [^ '\\' '\''] "'"
+ | "'" [^ '\\'] "'"
{ action lexbuf }
- | "'" '\\' backslash_escapes "'"
+ | "'" '\\' ['\\' '\'' 'n' 't' 'b' 'r'] "'"
{ action lexbuf }
| "'" '\\' ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
{ action lexbuf }
@@ -177,7 +164,7 @@ and string = parse
{ line_start_pos := Lexing.lexeme_end lexbuf;
incr line_num;
string lexbuf }
- | '\\' backslash_escapes
+ | '\\' ['\\' '"' 'n' 't' 'b' 'r']
{ store_string_char(char_for_backslash(Lexing.lexeme_char lexbuf 1));
string lexbuf }
| '\\' ['0'-'9'] ['0'-'9'] ['0'-'9']
@@ -190,13 +177,6 @@ and string = parse
line_start_pos := Lexing.lexeme_end lexbuf;
incr line_num;
string lexbuf }
- | '\\' _
- { warning lexbuf
- (Printf.sprintf "illegal backslash escape in string: `\\%c'"
- (Lexing.lexeme_char lexbuf 1));
- store_string_char(Lexing.lexeme_char lexbuf 0);
- store_string_char(Lexing.lexeme_char lexbuf 1);
- string lexbuf }
| _
{ store_string_char(Lexing.lexeme_char lexbuf 0);
string lexbuf }
@@ -216,7 +196,7 @@ and comment = parse
{ comment lexbuf }
| "'" [^ '\\' '\''] "'"
{ comment lexbuf }
- | "'\\" backslash_escapes "'"
+ | "'\\" ['\\' '\'' 'n' 't' 'b' 'r'] "'"
{ comment lexbuf }
| "'\\" ['0'-'9'] ['0'-'9'] ['0'-'9'] "'"
{ comment lexbuf }