diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-06-08 12:27:08 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-06-08 12:27:08 -0400 |
commit | 32115a531d5ed6cafa25dc7d3b88c2679e5142a5 (patch) | |
tree | 17f75e04d2559dc15a0f184c1c7da266de8a5a16 /src/lacweb.lex | |
parent | c060d15003e3435d4d4c770d8f109f756db13ef5 (diff) |
Primitive type constants
Diffstat (limited to 'src/lacweb.lex')
-rw-r--r-- | src/lacweb.lex | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/lacweb.lex b/src/lacweb.lex index 5234db3d..af2ed464 100644 --- a/src/lacweb.lex +++ b/src/lacweb.lex @@ -59,14 +59,19 @@ in end end +val str = ref ([] : char list) +val strStart = ref 0 + %% %header (functor LacwebLexFn(structure Tokens : Lacweb_TOKENS)); %full -%s COMMENT; +%s COMMENT STRING; id = [a-z_][A-Za-z0-9_]*; cid = [A-Z][A-Za-z0-9_]*; ws = [\ \t\012]; +intconst = [0-9]+; +realconst = [0-9]+\.[0-9]*; %% @@ -88,6 +93,14 @@ ws = [\ \t\012]; <COMMENT> "*)" => (if exitComment () then YYBEGIN INITIAL else (); continue ()); +<INITIAL> "\"" => (YYBEGIN STRING; strStart := yypos; str := []; continue()); +<STRING> "\\\"" => (str := #"\"" :: !str; continue()); +<STRING> "\"" => (YYBEGIN INITIAL; + Tokens.STRING (String.implode (List.rev (!str)), !strStart, yypos + 1)); +<STRING> "\n" => (ErrorMsg.newline yypos; + str := #"\n" :: !str; continue()); +<STRING> . => (str := String.sub (yytext, 0) :: !str; continue()); + <INITIAL> "(" => (Tokens.LPAREN (yypos, yypos + size yytext)); <INITIAL> ")" => (Tokens.RPAREN (yypos, yypos + size yytext)); <INITIAL> "[" => (Tokens.LBRACK (yypos, yypos + size yytext)); @@ -119,6 +132,17 @@ ws = [\ \t\012]; <INITIAL> {id} => (Tokens.SYMBOL (yytext, yypos, yypos + size yytext)); <INITIAL> {cid} => (Tokens.CSYMBOL (yytext, yypos, yypos + size yytext)); +<INITIAL> {intconst} => (case Int64.fromString yytext of + SOME x => Tokens.INT (x, yypos, yypos + size yytext) + | NONE => (ErrorMsg.errorAt' (yypos, yypos) + ("Expected int, received: " ^ yytext); + continue ())); +<INITIAL> {realconst} => (case Real64.fromString yytext of + SOME x => Tokens.FLOAT (x, yypos, yypos + size yytext) + | NONE => (ErrorMsg.errorAt' (yypos, yypos) + ("Expected float, received: " ^ yytext); + continue ())); + <COMMENT> . => (continue()); <INITIAL> . => (ErrorMsg.errorAt' (yypos, yypos) |