diff options
Diffstat (limited to 'src/Parser.hs')
-rw-r--r-- | src/Parser.hs | 29 |
1 files changed, 1 insertions, 28 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index f83f4cc..94de680 100644 --- a/src/Parser.hs +++ b/src/Parser.hs | |||
@@ -1,5 +1,4 @@ | |||
1 | module Parser ( parseLispValue | 1 | module Parser ( parseLispValue |
2 | , Expr(..) | ||
3 | , parseString | 2 | , parseString |
4 | , parseInt | 3 | , parseInt |
5 | , parseFloat | 4 | , parseFloat |
@@ -7,22 +6,10 @@ module Parser ( parseLispValue | |||
7 | , parseQuote | 6 | , parseQuote |
8 | ) where | 7 | ) where |
9 | 8 | ||
9 | import Base (Expr (..), Function) | ||
10 | import Control.Applicative ((<$>)) | 10 | import Control.Applicative ((<$>)) |
11 | import Text.ParserCombinators.Parsec | 11 | import Text.ParserCombinators.Parsec |
12 | 12 | ||
13 | -- TODO: use LispNumber (src/Operators.hs) here instead of IntLiteral and FloatLiteral | ||
14 | -- TODO: add character literals: \#a \#b \#c \#space \#newline | ||
15 | -- TODO: add support for complex numbers, oct and hex numbers | ||
16 | data Expr = List [Expr] | ||
17 | | Vector [Expr] | ||
18 | | DottedList [Expr] Expr | ||
19 | | StringLiteral String | ||
20 | | IntLiteral Integer | ||
21 | | FloatLiteral Double | ||
22 | | BoolLiteral Bool | ||
23 | | Id String | ||
24 | deriving (Eq) | ||
25 | |||
26 | -- backslash double quote escapes a quote inside strings | 13 | -- backslash double quote escapes a quote inside strings |
27 | quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') | 14 | quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') |
28 | 15 | ||
@@ -92,7 +79,6 @@ parseQuote = parseModifier "'" "quote" | |||
92 | parseQuasiquote = parseModifier "`" "quasiquote" | 79 | parseQuasiquote = parseModifier "`" "quasiquote" |
93 | parseUnquote = parseModifier "," "unquote" | 80 | parseUnquote = parseModifier "," "unquote" |
94 | parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" | 81 | parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" |
95 | -- TODO: add modifier for unquote splicing: ,@ | ||
96 | 82 | ||
97 | parseLispValue :: Parser Expr | 83 | parseLispValue :: Parser Expr |
98 | parseLispValue = | 84 | parseLispValue = |
@@ -114,16 +100,3 @@ parseLispValue = | |||
114 | return $ maybe (List x) (DottedList x) t | 100 | return $ maybe (List x) (DottedList x) t |
115 | <?> "lisp value" | 101 | <?> "lisp value" |
116 | 102 | ||
117 | showLispList :: [Expr] -> String | ||
118 | showLispList = unwords . map show | ||
119 | |||
120 | instance Show Expr where | ||
121 | show (DottedList xs x) = "(" ++ showLispList xs ++ " . " ++ show x ++ ")" | ||
122 | show (List xs) = "(" ++ showLispList xs ++ ")" | ||
123 | show (Vector xs) = "#(" ++ showLispList xs ++ ")" | ||
124 | show (StringLiteral s) = "\"" ++ s ++ "\"" | ||
125 | show (IntLiteral n) = show n | ||
126 | show (FloatLiteral n) = show n | ||
127 | show (BoolLiteral True) = "#t" | ||
128 | show (BoolLiteral False) = "#f" | ||
129 | show (Id i) = i | ||