X-Git-Url: http://git.joshuawise.com/snipe.git/blobdiff_plain/4f528370c7d70f4fd271c7ce5eee517284852940..2ab9671fde5297fc59583361f152e812e66c2d17:/parse/l5.lex diff --git a/parse/l5.lex b/parse/l5.lex index e10f8b7..3028a6c 100644 --- a/parse/l5.lex +++ b/parse/l5.lex @@ -17,6 +17,9 @@ type lexresult = (svalue,pos) Tokens.token local val commentLevel = ref 0 val commentPos = ref 0 + val inString = ref false + val stringPos = ref 0 + val stringAcc : string list ref = ref [] (* :( *) in fun enterComment yypos = ( commentLevel := !commentLevel + 1 ; @@ -62,14 +65,20 @@ in ( if (!commentLevel > 0) then (ErrorMsg.error (ParseState.ext (!commentPos,!commentPos)) "unterminated comment") else (); + if (!inString) + then (ErrorMsg.error (ParseState.ext (!stringPos,!stringPos)) "unterminated string") + else (); Tokens.EOF (0,0) ) (* bogus position information; unused *) + fun newString yyp = ( inString := true; stringPos := yyp; stringAcc := [] ) + fun endString yyp = ( Tokens.STRING (concat (rev (!stringAcc)), !stringPos, yyp+1) ) + fun addString yyt = ( inString := false; stringAcc := yyt :: (!stringAcc) ) end %% %header (functor L5LexFn(structure Tokens : L5_TOKENS)); %full -%s COMMENT COMMENT_LINE; +%s COMMENT COMMENT_LINE STRING; id = [A-Za-z_][A-Za-z0-9_]*; decnum = [0-9][0-9]*; @@ -143,6 +152,7 @@ ws = [\ \t\012]; "else" => (Tokens.ELSE (yypos, yypos + size yytext)); "var" => (Tokens.VAR (yypos, yypos + size yytext)); "int" => (Tokens.INT (yypos, yypos + size yytext)); + "string" => (Tokens.TSTRING (yypos, yypos + size yytext)); "extern" => (Tokens.EXTERN (yypos, yypos + size yytext)); "struct" => (Tokens.STRUCT (yypos, yypos + size yytext)); "NULL" => (Tokens.NULL (yypos, yypos + size yytext)); @@ -164,10 +174,12 @@ ws = [\ \t\012]; "//" => (YYBEGIN COMMENT_LINE; lex()); "#" => (YYBEGIN COMMENT_LINE; lex()); + "\"" => (YYBEGIN STRING; newString yypos ; lex () ); . => (ErrorMsg.error (ParseState.ext (yypos,yypos)) ("illegal character: \"" ^ yytext ^ "\""); lex ()); + "/*" => (enterComment yypos; lex()); "*/" => (if exitComment () then YYBEGIN INITIAL else (); lex()); \n => (ParseState.newline yypos; lex ()); @@ -175,3 +187,6 @@ ws = [\ \t\012]; \n => (ParseState.newline yypos; YYBEGIN INITIAL; lex()); . => (lex()); + + [^\"\\]* => (addString yytext ; lex() ); + "\"" => (YYBEGIN INITIAL; endString yypos );