Mercurial > urweb
diff src/lacweb.lex @ 14:f1c36df29ed7
Primitive type constants
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 08 Jun 2008 12:27:08 -0400 |
parents | a455a9f85cc3 |
children | 9a578171de9e |
line wrap: on
line diff
--- a/src/lacweb.lex Sun Jun 08 11:32:48 2008 -0400 +++ b/src/lacweb.lex Sun Jun 08 12:27:08 2008 -0400 @@ -59,14 +59,19 @@ 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 @@ <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 @@ <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)