From 40f97e49084e04f74f12dd9bccd05c9da11dd591 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 28 May 2015 10:23:43 -0400 Subject: Handling overflow in integer literals (contributed by Gabriel Riba) --- src/urweb.lex | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/urweb.lex') diff --git a/src/urweb.lex b/src/urweb.lex index e1ffd1c3..fcf10d94 100644 --- a/src/urweb.lex +++ b/src/urweb.lex @@ -182,7 +182,7 @@ cid = [A-Z][A-Za-z0-9_]*; ws = [\ \t\012\r]; intconst = [0-9]+; realconst = [0-9]+\.[0-9]*; -hexconst = 0x[0-9A-F]{1,8}; +hexconst = 0x[0-9A-F]+; notags = ([^<{\n(]|(\([^\*<{\n]))+; xcom = ([^\-]|(-[^\-]))+; oint = [0-9][0-9][0-9]; @@ -542,17 +542,25 @@ xint = x[0-9a-fA-F][0-9a-fA-F]; {id} => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext)); {cid} => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext)); - {hexconst} => (case StringCvt.scanString (Int64.scan StringCvt.HEX) (String.extract (yytext, 2, NONE)) of + {hexconst} => (let val digits = String.extract (yytext, 2, NONE) + val v = (StringCvt.scanString (Int64.scan StringCvt.HEX) digits) + handle Overflow => NONE + in + case v of SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext) | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) ("Expected hexInt, received: " ^ yytext); - continue ())); + continue ()) + end); - {intconst} => (case Int64.fromString yytext of + {intconst} => (let val v = (Int64.fromString yytext) handle Overflow => NONE + in + case v of SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext) | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) ("Expected int, received: " ^ yytext); - continue ())); + continue ()) + end); {realconst} => (case Real64.fromString yytext of SOME x => Tokens.FLOAT (x, pos yypos, pos yypos + size yytext) | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) -- cgit v1.2.3 From 57424b901657e7c798fc7e4b20427c2d42835203 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 28 May 2015 10:28:15 -0400 Subject: Remove duplicate lexer line --- src/urweb.lex | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/urweb.lex') diff --git a/src/urweb.lex b/src/urweb.lex index fcf10d94..c44a4c1d 100644 --- a/src/urweb.lex +++ b/src/urweb.lex @@ -537,8 +537,6 @@ xint = x[0-9a-fA-F][0-9a-fA-F]; "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext)); - "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext)); - {id} => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext)); {cid} => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext)); -- cgit v1.2.3 From de90e13f1cd152318791f47d75280f03e768c7cc Mon Sep 17 00:00:00 2001 From: Gabriel Riba Faura Date: Wed, 3 Jun 2015 08:34:23 +0200 Subject: location literal _LOC_ --- src/urweb.lex | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/urweb.lex') diff --git a/src/urweb.lex b/src/urweb.lex index c44a4c1d..eada3611 100644 --- a/src/urweb.lex +++ b/src/urweb.lex @@ -537,6 +537,12 @@ xint = x[0-9a-fA-F][0-9a-fA-F]; "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext)); + "_LOC_" => (let val strLoc = ErrorMsg.spanToString (ErrorMsg.spanOf + (pos yypos, pos yypos + size yytext)) + in + Tokens.STRING (strLoc, pos yypos, pos yypos + size yytext) + end); + {id} => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext)); {cid} => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext)); -- cgit v1.2.3 From 443fa1a2ad02b653c96de2fb159fbdb510a87171 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 11 Jun 2015 19:06:32 -0400 Subject: Allow apostrophes in capitalized identifiers --- src/urweb.lex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/urweb.lex') diff --git a/src/urweb.lex b/src/urweb.lex index eada3611..f32ddf1e 100644 --- a/src/urweb.lex +++ b/src/urweb.lex @@ -178,7 +178,7 @@ fun unescape loc s = id = [a-z_][A-Za-z0-9_']*; xmlid = [A-Za-z][A-Za-z0-9_-]*; -cid = [A-Z][A-Za-z0-9_]*; +cid = [A-Z][A-Za-z0-9_']*; ws = [\ \t\012\r]; intconst = [0-9]+; realconst = [0-9]+\.[0-9]*; -- cgit v1.2.3