diff options
author | Atreya Bain <[email protected]> | 2020-10-26 07:23:38 +0000 |
---|---|---|
committer | Atreya Bain <[email protected]> | 2020-10-26 07:23:38 +0000 |
commit | 61eb6abb4eea4ef2c8f03b33976ebf723011ed56 (patch) | |
tree | 805c87ded9e457bcc8ee94a9eadbbefe998656fb /src | |
parent | fbdd64d7e0888dd106abe8da7a7c46ec032db1ea (diff) |
add comments as whitespace
Diffstat (limited to 'src')
-rw-r--r-- | src/Parser.hs | 31 |
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 | ||
9 | import Base (Expr (..), Function) | 10 | import Base (Expr (..), Function) |
10 | import Control.Applicative ((<$>)) | 11 | import Control.Applicative ((<$>)) |
11 | import Text.ParserCombinators.Parsec | 12 | import Text.ParserCombinators.Parsec |
12 | 13 | ||
14 | |||
15 | parseComment :: Parser () | ||
16 | parseComment = 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 |
14 | quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') | 23 | quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') |
15 | 24 | ||
@@ -63,10 +72,14 @@ parseId = do | |||
63 | _ -> Id atom | 72 | _ -> Id atom |
64 | 73 | ||
65 | whiteSpace :: Parser () | 74 | whiteSpace :: Parser () |
66 | whiteSpace = skipMany1 $ oneOf [' ', '\n'] | 75 | whiteSpace = |
76 | skipMany1 ( oneOf [' ', '\n']) | ||
77 | <|> parseComment | ||
67 | 78 | ||
68 | optionalWhiteSpace :: Parser () | 79 | optionalWhiteSpace :: Parser () |
69 | optionalWhiteSpace = skipMany $ oneOf [' ', '\n'] | 80 | optionalWhiteSpace = |
81 | skipMany ( oneOf [' ', '\n']) | ||
82 | <|> parseComment | ||
70 | 83 | ||
71 | type Alias = String | 84 | type Alias = String |
72 | parseModifier :: String -> Alias -> Parser Expr | 85 | parseModifier :: String -> Alias -> Parser Expr |
@@ -80,9 +93,15 @@ parseQuasiquote = parseModifier "`" "quasiquote" | |||
80 | parseUnquote = parseModifier "," "unquote" | 93 | parseUnquote = parseModifier "," "unquote" |
81 | parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" | 94 | parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" |
82 | 95 | ||
96 | -- parseLispValue = do | ||
97 | -- pepe <- parseLispValueNoComments | ||
98 | -- try parseComment | ||
99 | -- return pepe | ||
100 | |||
101 | |||
83 | parseLispValue :: Parser Expr | 102 | parseLispValue :: Parser Expr |
84 | parseLispValue = | 103 | parseLispValue = |
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 | ||