diff options
author | Atreya Bain <[email protected]> | 2020-10-27 14:56:01 +0000 |
---|---|---|
committer | Atreya Bain <[email protected]> | 2020-10-27 14:56:01 +0000 |
commit | ed32b282a7bf62ea8c66dd8f39fc1b03afbfc478 (patch) | |
tree | 9433bbdd7f8df33af3efd0a945f3d42cd869499d | |
parent | 1de9cdfcb7fc8c30bd05e017929dae862d847c95 (diff) |
add newline consumption
-rw-r--r-- | src/Parser.hs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index 34d90ba..cf58a2b 100644 --- a/src/Parser.hs +++ b/src/Parser.hs | |||
@@ -10,6 +10,7 @@ module Parser ( parseLispValue | |||
10 | import Base (Expr (..), Function) | 10 | import Base (Expr (..), Function) |
11 | import Control.Applicative ((<$>)) | 11 | import Control.Applicative ((<$>)) |
12 | import Text.ParserCombinators.Parsec | 12 | import Text.ParserCombinators.Parsec |
13 | import Text.Parsec.Char | ||
13 | 14 | ||
14 | 15 | ||
15 | 16 | ||
@@ -69,16 +70,22 @@ parseId = do | |||
69 | parseComment :: Parser () | 70 | parseComment :: Parser () |
70 | parseComment = do | 71 | parseComment = do |
71 | char ';' | 72 | char ';' |
72 | skipMany (noneOf ['\n']) | 73 | -- get internals of comment by getting it from here |
73 | -- skipMany $ char '\n' | 74 | manyTill anyChar (try (eol<|> eof)) |
74 | return () | 75 | return () |
76 | where eol = endOfLine >>return () | ||
75 | 77 | ||
76 | 78 | ||
77 | whiteSpace :: Parser () | 79 | -- whiteSpace :: Parser () |
78 | whiteSpace = do | 80 | -- whiteSpace = do |
79 | optionMaybe parseComment | 81 | -- optionMaybe parseComment |
80 | skipMany1 ( oneOf [' ', '\n']) <?> "whitespace or newline" | 82 | -- skipMany1 ( oneOf [' ', '\n']) <?> "whitespace or endOfLine" |
81 | return () | 83 | -- return () |
84 | whiteSpace::Parser() | ||
85 | whiteSpace = skipMany( parseComment <|> nl <|> spc ) | ||
86 | where nl = endOfLine >>return () | ||
87 | spc = space >> return () | ||
88 | |||
82 | 89 | ||
83 | optionalWhiteSpace :: Parser () | 90 | optionalWhiteSpace :: Parser () |
84 | optionalWhiteSpace = do | 91 | optionalWhiteSpace = do |