Mercurial > urweb
comparison src/urweb.lex @ 2148:a49c12ddf47d
Handling overflow in integer literals (contributed by Gabriel Riba)
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Thu, 28 May 2015 10:23:43 -0400 |
parents | f3c24e6790ba |
children | 854d7ba67a59 |
comparison
equal
deleted
inserted
replaced
2147:265c1aeed71b | 2148:a49c12ddf47d |
---|---|
180 xmlid = [A-Za-z][A-Za-z0-9_-]*; | 180 xmlid = [A-Za-z][A-Za-z0-9_-]*; |
181 cid = [A-Z][A-Za-z0-9_]*; | 181 cid = [A-Z][A-Za-z0-9_]*; |
182 ws = [\ \t\012\r]; | 182 ws = [\ \t\012\r]; |
183 intconst = [0-9]+; | 183 intconst = [0-9]+; |
184 realconst = [0-9]+\.[0-9]*; | 184 realconst = [0-9]+\.[0-9]*; |
185 hexconst = 0x[0-9A-F]{1,8}; | 185 hexconst = 0x[0-9A-F]+; |
186 notags = ([^<{\n(]|(\([^\*<{\n]))+; | 186 notags = ([^<{\n(]|(\([^\*<{\n]))+; |
187 xcom = ([^\-]|(-[^\-]))+; | 187 xcom = ([^\-]|(-[^\-]))+; |
188 oint = [0-9][0-9][0-9]; | 188 oint = [0-9][0-9][0-9]; |
189 xint = x[0-9a-fA-F][0-9a-fA-F]; | 189 xint = x[0-9a-fA-F][0-9a-fA-F]; |
190 | 190 |
540 <INITIAL> "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext)); | 540 <INITIAL> "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext)); |
541 | 541 |
542 <INITIAL> {id} => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext)); | 542 <INITIAL> {id} => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext)); |
543 <INITIAL> {cid} => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext)); | 543 <INITIAL> {cid} => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext)); |
544 | 544 |
545 <INITIAL> {hexconst} => (case StringCvt.scanString (Int64.scan StringCvt.HEX) (String.extract (yytext, 2, NONE)) of | 545 <INITIAL> {hexconst} => (let val digits = String.extract (yytext, 2, NONE) |
546 val v = (StringCvt.scanString (Int64.scan StringCvt.HEX) digits) | |
547 handle Overflow => NONE | |
548 in | |
549 case v of | |
546 SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext) | 550 SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext) |
547 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) | 551 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) |
548 ("Expected hexInt, received: " ^ yytext); | 552 ("Expected hexInt, received: " ^ yytext); |
549 continue ())); | 553 continue ()) |
550 | 554 end); |
551 <INITIAL> {intconst} => (case Int64.fromString yytext of | 555 |
556 <INITIAL> {intconst} => (let val v = (Int64.fromString yytext) handle Overflow => NONE | |
557 in | |
558 case v of | |
552 SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext) | 559 SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext) |
553 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) | 560 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) |
554 ("Expected int, received: " ^ yytext); | 561 ("Expected int, received: " ^ yytext); |
555 continue ())); | 562 continue ()) |
563 end); | |
556 <INITIAL> {realconst} => (case Real64.fromString yytext of | 564 <INITIAL> {realconst} => (case Real64.fromString yytext of |
557 SOME x => Tokens.FLOAT (x, pos yypos, pos yypos + size yytext) | 565 SOME x => Tokens.FLOAT (x, pos yypos, pos yypos + size yytext) |
558 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) | 566 | NONE => (ErrorMsg.errorAt' (pos yypos, pos yypos) |
559 ("Expected float, received: " ^ yytext); | 567 ("Expected float, received: " ^ yytext); |
560 continue ())); | 568 continue ())); |