From 74b380efbcbdc1bb2558c2c5bced43fd36dff6fb Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Tue, 14 Feb 2023 17:05:01 +1300 Subject: Add lexing for negative integers --- DSL.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'DSL.hs') 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 -- cgit v1.2.1