Writing a port of Haskell's Data.Hashable I missed hexadecimal constants.

This version note of smlnj says that only uppercase hexadecimal digits are admitted: http://www.smlnj.org/dist/working/110.57/110.57-README.html

Also here is an SML grammar specification that tells the same: http://www.mpi-sws.org/~rossberg/sml.html

So I would add to the definitions

hexconst = 0x[0-9A-F]{1,8};

And to the rules,

<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 hexadecimal int, received: " ^ yytext);

(* --- *)

just preceding the {intconst} rule although the manual states that the longest match is chosen.

Tested.

--- ../../urweb-20150214/src/urweb.lex	2014-12-06 21:28:52.000000000 +0100
+++ urweb-20150214/src/urweb.lex	2015-02-26 18:38:56.347707891 +0100
@@ -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];
@@ -532,6 +533,11 @@
 <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 hexadecimal int, received: " ^ yytext);
+
 <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)
_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to