mirror of
https://github.com/edwinb/Idris2-boot.git
synced 2024-11-24 12:54:28 +03:00
Support hex literals in the parser
This commit is contained in:
parent
2465e5a149
commit
b1c37b00ca
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user