diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-18 00:11:29 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-18 00:11:29 +1300 |
| commit | 69276220df02d2c226021d79ee4a4fd173ae85ee (patch) | |
| tree | a53bf65216fcbc0ed11d19e90daf9a4be31d6019 /DSL/Parsing.hs | |
| parent | c8e97a9e6ebfefec0db5bc51bd095b3d10dfd078 (diff) | |
String literals, fizzbuzz, other tweaks
Diffstat (limited to 'DSL/Parsing.hs')
| -rw-r--r-- | DSL/Parsing.hs | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/DSL/Parsing.hs b/DSL/Parsing.hs index ef7da9e..76acacd 100644 --- a/DSL/Parsing.hs +++ b/DSL/Parsing.hs @@ -19,11 +19,13 @@ fromTableL table = firstOf $ map (uncurry fromStringL) table wsL :: DSLLexer wsL = buildDSLLexer (mult1 $ satisfy isSpace) T_WHITESPACE -boolLiteralL :: DSLLexer -boolLiteralL = t `alt` f - where - t = buildDSLLexer (list "true") T_BOOL_LITERAL - f = buildDSLLexer (list "false") T_BOOL_LITERAL +keywordL :: DSLLexer +keywordL = fromTableL [ ("IF", T_IF) + , ("ELSE", T_ELSE) + , ("WHILE", T_WHILE) + , ("DO", T_DO) + , ("END", T_END) + ] intLiteralL :: DSLLexer intLiteralL = buildDSLLexer go T_INT_LITERAL @@ -33,17 +35,22 @@ intLiteralL = buildDSLLexer go T_INT_LITERAL digits <- mult1 $ satisfy isDigit result $ maybe digits (:digits) sign -keywordL :: DSLLexer -keywordL = fromTableL [ ("IF", T_IF) - , ("ELSE", T_ELSE) - , ("WHILE", T_WHILE) - , ("DO", T_DO) - , ("END", T_END) - ] +boolLiteralL :: DSLLexer +boolLiteralL = f "true" `alt` f "false" + where + f s = fromStringL s T_BOOL_LITERAL + +stringLiteralL :: DSLLexer +stringLiteralL = buildDSLLexer go T_STRING_LITERAL + where + go = token '"' *> strChars <* token '"' + strChars = concat <$> mult strChar + strChar = list ['\\', '"'] `alt` (pure <$> satisfy (/='"')) literalL :: DSLLexer -literalL = firstOf [ boolLiteralL - , intLiteralL +literalL = firstOf [ intLiteralL + , boolLiteralL + , stringLiteralL ] intrinsicL :: DSLLexer @@ -92,6 +99,7 @@ dataLiteralP = do (T_BOOL_LITERAL, "true") -> result $ StackBool True (T_BOOL_LITERAL, "false") -> result $ StackBool False (T_INT_LITERAL, _) -> result $ StackInt $ read s + (T_STRING_LITERAL, _) -> result $ StackString s _ -> flunk pushDataP :: DSLParser Operation |
