diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-14 17:05:01 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-14 17:05:01 +1300 |
| commit | 74b380efbcbdc1bb2558c2c5bced43fd36dff6fb (patch) | |
| tree | 82020dc5118ec33142a661e317128849ce6c175f | |
| parent | 86d4ffc8a450a1679a8304cc2f2ab9559c38d919 (diff) | |
Add lexing for negative integers
| -rw-r--r-- | DSL.hs | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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 |
