aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtreya Bain <[email protected]>2020-10-26 07:23:38 +0000
committerAtreya Bain <[email protected]>2020-10-26 07:23:38 +0000
commit61eb6abb4eea4ef2c8f03b33976ebf723011ed56 (patch)
tree805c87ded9e457bcc8ee94a9eadbbefe998656fb
parentfbdd64d7e0888dd106abe8da7a7c46ec032db1ea (diff)
add comments as whitespace
-rw-r--r--src/Parser.hs31
1 files 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
4 , parseFloat 4 , parseFloat
5 , parseId 5 , parseId
6 , parseQuote 6 , parseQuote
7 , parseComment
7 ) where 8 ) where
8 9
9import Base (Expr (..), Function) 10import Base (Expr (..), Function)
10import Control.Applicative ((<$>)) 11import Control.Applicative ((<$>))
11import Text.ParserCombinators.Parsec 12import Text.ParserCombinators.Parsec
12 13
14
15parseComment :: Parser ()
16parseComment = do
17 char ';'
18 innards <- many (noneOf ['\n'])
19 return ()
20
21
13-- backslash double quote escapes a quote inside strings 22-- backslash double quote escapes a quote inside strings
14quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') 23quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"')
15 24
@@ -63,10 +72,14 @@ parseId = do
63 _ -> Id atom 72 _ -> Id atom
64 73
65whiteSpace :: Parser () 74whiteSpace :: Parser ()
66whiteSpace = skipMany1 $ oneOf [' ', '\n'] 75whiteSpace =
76 skipMany1 ( oneOf [' ', '\n'])
77 <|> parseComment
67 78
68optionalWhiteSpace :: Parser () 79optionalWhiteSpace :: Parser ()
69optionalWhiteSpace = skipMany $ oneOf [' ', '\n'] 80optionalWhiteSpace =
81 skipMany ( oneOf [' ', '\n'])
82 <|> parseComment
70 83
71type Alias = String 84type Alias = String
72parseModifier :: String -> Alias -> Parser Expr 85parseModifier :: String -> Alias -> Parser Expr
@@ -80,9 +93,15 @@ parseQuasiquote = parseModifier "`" "quasiquote"
80parseUnquote = parseModifier "," "unquote" 93parseUnquote = parseModifier "," "unquote"
81parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" 94parseUnquoteSplicing = parseModifier ",@" "unquote-splicing"
82 95
96-- parseLispValue = do
97-- pepe <- parseLispValueNoComments
98-- try parseComment
99-- return pepe
100
101
83parseLispValue :: Parser Expr 102parseLispValue :: Parser Expr
84parseLispValue = 103parseLispValue =
85 parseString 104 parseString
86 <|> try parseFloat 105 <|> try parseFloat
87 <|> try parseInt 106 <|> try parseInt
88 <|> try parseVector 107 <|> try parseVector
@@ -98,5 +117,7 @@ parseLispValue =
98 t <- optionMaybe $ char '.' >> space >> parseLispValue 117 t <- optionMaybe $ char '.' >> space >> parseLispValue
99 optionalWhiteSpace >> char ')' 118 optionalWhiteSpace >> char ')'
100 return $ maybe (List x) (DottedList x) t 119 return $ maybe (List x) (DottedList x) t
101 <?> "lisp value" 120 <?> "lisp value";
121 -- try parseComment;
122 -- return pepe;
102 123