summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-02-14 17:05:01 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-02-14 17:05:01 +1300
commit74b380efbcbdc1bb2558c2c5bced43fd36dff6fb (patch)
tree82020dc5118ec33142a661e317128849ce6c175f
parent86d4ffc8a450a1679a8304cc2f2ab9559c38d919 (diff)
Add lexing for negative integers
-rw-r--r--DSL.hs7
1 files changed, 6 insertions, 1 deletions
diff --git a/DSL.hs b/DSL.hs
index 3244c7f..ea4c8c2 100644
--- a/DSL.hs
+++ b/DSL.hs
@@ -82,7 +82,12 @@ wsL :: DSLLexer
wsL = buildDSLLexer (mult1 $ satisfy isSpace) (const T_WHITESPACE)
intLiteralL :: DSLLexer
-intLiteralL = buildDSLLexer (mult1 $ satisfy isDigit) (T_INT_LITERAL . read)
+intLiteralL = buildDSLLexer go (T_INT_LITERAL . read)
+ where
+ go = do
+ sign <- optional $ token '-'
+ digits <- mult1 $ satisfy isDigit
+ result $ maybe digits (:digits) sign
mainLexer :: Parser Char [DSLToken]
mainLexer = phrase $ mult1 $ firstOf subLexers