Support hex literals in the parser

This commit is contained in:
Edwin Brady 2020-01-31 18:15:19 +00:00
parent 2465e5a149
commit b1c37b00ca

View File

@ -1,6 +1,7 @@
module Parser.Lexer
import public Text.Lexer
import Utils.Hex
%default total
@ -138,6 +139,15 @@ reservedSymbols
symbolChar : Char -> Bool
symbolChar c = c `elem` unpack opChars
fromHexLit : String -> Integer
fromHexLit str
= if length str <= 2
then 0
else let num = assert_total (strTail (strTail str)) in
case fromHex (reverse num) of
Nothing => 0 -- can't happen if the literal lexed correctly
Just n => cast n
rawTokens : TokenMap Token
rawTokens =
[(comment, Comment),
@ -147,6 +157,7 @@ rawTokens =
(holeIdent, \x => HoleIdent (assert_total (strTail x)))] ++
map (\x => (exact x, Symbol)) symbols ++
[(doubleLit, \x => DoubleLit (cast x)),
(hexLit, \x => Literal (fromHexLit x)),
(digits, \x => Literal (cast x)),
(stringLit, \x => StrLit (stripQuotes x)),
(charLit, \x => CharLit (stripQuotes x)),