diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Parser.hs | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index cf58a2b..dfc3225 100644 --- a/src/Parser.hs +++ b/src/Parser.hs | |||
@@ -9,10 +9,9 @@ module Parser ( parseLispValue | |||
9 | 9 | ||
10 | import Base (Expr (..), Function) | 10 | import Base (Expr (..), Function) |
11 | import Control.Applicative ((<$>)) | 11 | import Control.Applicative ((<$>)) |
12 | import Control.Monad (void) | ||
13 | import Text.Parsec.Char | ||
12 | import Text.ParserCombinators.Parsec | 14 | import Text.ParserCombinators.Parsec |
13 | import Text.Parsec.Char | ||
14 | |||
15 | |||
16 | 15 | ||
17 | -- backslash double quote escapes a quote inside strings | 16 | -- backslash double quote escapes a quote inside strings |
18 | quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') | 17 | quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') |
@@ -71,26 +70,16 @@ parseComment :: Parser () | |||
71 | parseComment = do | 70 | parseComment = do |
72 | char ';' | 71 | char ';' |
73 | -- get internals of comment by getting it from here | 72 | -- get internals of comment by getting it from here |
74 | manyTill anyChar (try (eol<|> eof)) | 73 | void $ manyTill anyChar $ try $ eol <|> eof |
75 | return () | 74 | where eol = void endOfLine |
76 | where eol = endOfLine >>return () | ||
77 | |||
78 | |||
79 | -- whiteSpace :: Parser () | ||
80 | -- whiteSpace = do | ||
81 | -- optionMaybe parseComment | ||
82 | -- skipMany1 ( oneOf [' ', '\n']) <?> "whitespace or endOfLine" | ||
83 | -- return () | ||
84 | whiteSpace::Parser() | ||
85 | whiteSpace = skipMany( parseComment <|> nl <|> spc ) | ||
86 | where nl = endOfLine >>return () | ||
87 | spc = space >> return () | ||
88 | 75 | ||
76 | whiteSpace::Parser() | ||
77 | whiteSpace = skipMany $ parseComment <|> nl <|> spc | ||
78 | where nl = void endOfLine | ||
79 | spc = void space | ||
89 | 80 | ||
90 | optionalWhiteSpace :: Parser () | 81 | optionalWhiteSpace :: Parser () |
91 | optionalWhiteSpace = do | 82 | optionalWhiteSpace = void $ optionMaybe whiteSpace |
92 | optionMaybe $ whiteSpace | ||
93 | return () | ||
94 | 83 | ||
95 | type Alias = String | 84 | type Alias = String |
96 | parseModifier :: String -> Alias -> Parser Expr | 85 | parseModifier :: String -> Alias -> Parser Expr |
@@ -105,7 +94,7 @@ parseUnquote = parseModifier "," "unquote" | |||
105 | parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" | 94 | parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" |
106 | 95 | ||
107 | parseLispValue :: Parser Expr | 96 | parseLispValue :: Parser Expr |
108 | parseLispValue = | 97 | parseLispValue = |
109 | parseString | 98 | parseString |
110 | <|> try parseFloat | 99 | <|> try parseFloat |
111 | <|> try parseInt | 100 | <|> try parseInt |