aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Parser.hs31
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
10import Base (Expr (..), Function) 10import Base (Expr (..), Function)
11import Control.Applicative ((<$>)) 11import Control.Applicative ((<$>))
12import Control.Monad (void)
13import Text.Parsec.Char
12import Text.ParserCombinators.Parsec 14import Text.ParserCombinators.Parsec
13import 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
18quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') 17quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"')
@@ -71,26 +70,16 @@ parseComment :: Parser ()
71parseComment = do 70parseComment = 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 ()
84whiteSpace::Parser()
85whiteSpace = skipMany( parseComment <|> nl <|> spc )
86 where nl = endOfLine >>return ()
87 spc = space >> return ()
88 75
76whiteSpace::Parser()
77whiteSpace = skipMany $ parseComment <|> nl <|> spc
78 where nl = void endOfLine
79 spc = void space
89 80
90optionalWhiteSpace :: Parser () 81optionalWhiteSpace :: Parser ()
91optionalWhiteSpace = do 82optionalWhiteSpace = void $ optionMaybe whiteSpace
92 optionMaybe $ whiteSpace
93 return ()
94 83
95type Alias = String 84type Alias = String
96parseModifier :: String -> Alias -> Parser Expr 85parseModifier :: String -> Alias -> Parser Expr
@@ -105,7 +94,7 @@ parseUnquote = parseModifier "," "unquote"
105parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" 94parseUnquoteSplicing = parseModifier ",@" "unquote-splicing"
106 95
107parseLispValue :: Parser Expr 96parseLispValue :: Parser Expr
108parseLispValue = 97parseLispValue =
109 parseString 98 parseString
110 <|> try parseFloat 99 <|> try parseFloat
111 <|> try parseInt 100 <|> try parseInt