changeset 2124:f3c24e6790ba

Hexadecimal integer literals, contributed by Gabriel Riba
author Adam Chlipala <adam@chlipala.net>
date Thu, 05 Mar 2015 15:03:04 -0500 (2015-03-05)
parents 1218daa14279
children 15d46eb02570
files src/urweb.lex
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/urweb.lex	Thu Mar 05 14:58:34 2015 -0500
+++ b/src/urweb.lex	Thu Mar 05 15:03:04 2015 -0500
@@ -182,6 +182,7 @@
 ws = [\ \t\012\r];
 intconst = [0-9]+;
 realconst = [0-9]+\.[0-9]*;
+hexconst = 0x[0-9A-F]{1,8};
 notags = ([^<{\n(]|(\([^\*<{\n]))+;
 xcom = ([^\-]|(-[^\-]))+;
 oint = [0-9][0-9][0-9];
@@ -541,6 +542,12 @@
 <INITIAL> {id}        => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext));
 <INITIAL> {cid}       => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext));
 
+<INITIAL> {hexconst}  => (case StringCvt.scanString (Int64.scan StringCvt.HEX) (String.extract (yytext, 2, NONE)) of
+                              SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext)
+                            | NONE   => (ErrorMsg.errorAt' (pos yypos, pos yypos)
+                                                           ("Expected hexInt, received: " ^ yytext);
+                                         continue ()));
+
 <INITIAL> {intconst}  => (case Int64.fromString yytext of
                               SOME x => Tokens.INT (x, pos yypos, pos yypos + size yytext)
                             | NONE   => (ErrorMsg.errorAt' (pos yypos, pos yypos)