From 77d84c1539851f096b2c632cc6381ac72b2bfd1b Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Sat, 18 Feb 2023 17:35:13 +1300 Subject: Implement multline comments --- DSL/Parsing.hs | 14 ++++++++++++-- DSL/Types.hs | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'DSL') diff --git a/DSL/Parsing.hs b/DSL/Parsing.hs index fad68f1..6dcc4bf 100644 --- a/DSL/Parsing.hs +++ b/DSL/Parsing.hs @@ -19,6 +19,12 @@ fromTableL table = firstOf $ map (uncurry fromStringL) table wsL :: DSLLexer wsL = buildDSLLexer (mult1 $ satisfy isSpace) T_WHITESPACE +commentL :: DSLLexer +commentL = buildDSLLexer go T_COMMENT + where + delim = list "'''" + go = delim *> (fmap fst $ stopAfter delim) + keywordL :: DSLLexer keywordL = fromTableL [ ("PROC", T_PROC) , ("IF", T_IF) @@ -81,14 +87,18 @@ intrinsicL = fromTableL [ (".", T_INTRINSIC I_DUMP) ] lexemeL :: DSLLexer -lexemeL = firstOf [ keywordL +lexemeL = firstOf [ commentL + , keywordL , literalL , intrinsicL , identifierL ] tokenizer :: Parser Char [Token] -tokenizer = optional wsL *> lexemeL `sepBy` wsL <* optional wsL +tokenizer = filter f <$> go + where + go = optional wsL *> lexemeL `sepBy` wsL <* optional wsL + f Token { tTag=t } = t /= T_COMMENT ------------------------------------------------------------------------------ -- Parsing diff --git a/DSL/Types.hs b/DSL/Types.hs index 7bd9f56..dbed203 100644 --- a/DSL/Types.hs +++ b/DSL/Types.hs @@ -75,6 +75,7 @@ data Machine = Machine { ok :: Bool data TokenTag = T_WHITESPACE + | T_COMMENT | T_PROC | T_IF | T_ELSE -- cgit v1.2.1