From 61eb6abb4eea4ef2c8f03b33976ebf723011ed56 Mon Sep 17 00:00:00 2001 From: Atreya Bain Date: Mon, 26 Oct 2020 12:53:38 +0530 Subject: add comments as whitespace --- src/Parser.hs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Parser.hs b/src/Parser.hs index 94de680..67d302a 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -4,12 +4,21 @@ module Parser ( parseLispValue , parseFloat , parseId , parseQuote + , parseComment ) where import Base (Expr (..), Function) import Control.Applicative ((<$>)) import Text.ParserCombinators.Parsec + +parseComment :: Parser () +parseComment = do + char ';' + innards <- many (noneOf ['\n']) + return () + + -- backslash double quote escapes a quote inside strings quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') @@ -63,10 +72,14 @@ parseId = do _ -> Id atom whiteSpace :: Parser () -whiteSpace = skipMany1 $ oneOf [' ', '\n'] +whiteSpace = + skipMany1 ( oneOf [' ', '\n']) + <|> parseComment optionalWhiteSpace :: Parser () -optionalWhiteSpace = skipMany $ oneOf [' ', '\n'] +optionalWhiteSpace = + skipMany ( oneOf [' ', '\n']) + <|> parseComment type Alias = String parseModifier :: String -> Alias -> Parser Expr @@ -80,9 +93,15 @@ parseQuasiquote = parseModifier "`" "quasiquote" parseUnquote = parseModifier "," "unquote" parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" +-- parseLispValue = do +-- pepe <- parseLispValueNoComments +-- try parseComment +-- return pepe + + parseLispValue :: Parser Expr -parseLispValue = - parseString +parseLispValue = + parseString <|> try parseFloat <|> try parseInt <|> try parseVector @@ -98,5 +117,7 @@ parseLispValue = t <- optionMaybe $ char '.' >> space >> parseLispValue optionalWhiteSpace >> char ')' return $ maybe (List x) (DottedList x) t - "lisp value" + "lisp value"; + -- try parseComment; + -- return pepe; -- cgit v1.2.3