From 193210273df7156a6987853cd876a5199aee6117 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Mon, 9 Dec 2024 11:47:53 -0500 Subject: [PATCH] now presumably preprocessing with support for discarding comments --- src/RTLILParser/Parser.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/RTLILParser/Parser.hs b/src/RTLILParser/Parser.hs index 94f6dcd..970c543 100644 --- a/src/RTLILParser/Parser.hs +++ b/src/RTLILParser/Parser.hs @@ -1,4 +1,8 @@ -module RTLILParser.Parser(a, val) where +module RTLILParser.Parser( + preProcessDiscardComments, + pFile, + a, + val) where import Control.Monad (void) import Text.Parsec @@ -109,6 +113,16 @@ pString = parseString = many (pEscapedChar <|> noneOf "\\\"") -- comments +-- | Removes inline comments starting with '#' while preserving newlines +preProcessDiscardComments :: String -> String +preProcessDiscardComments input = unlines $ map stripComment $ lines input + where + -- Strips comments from a single line + stripComment line = case break (== '#') line of + (code, "") -> code -- No comment found + (code, _) -> code -- Strip everything after '#' + + -- file pFile :: Parser File pFile = File