[Ur] A simple patch for (int) hexadecimal constants

Gabriel Riba gabriel at xarxaire.com
Thu Feb 26 13:46:08 EST 2015


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: urweb.lex.patch
Type: text/x-diff
Size: 1191 bytes
Desc: not available
URL: <http://www.impredicative.com/pipermail/ur/attachments/20150226/07bdaada/attachment.patch>


More information about the Ur mailing list