aboutsummaryrefslogtreecommitdiff
path: root/src/Parser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Parser.hs')
-rw-r--r--src/Parser.hs29
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 @@
1module Parser ( parseLispValue 1module 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
9import Base (Expr (..), Function)
10import Control.Applicative ((<$>)) 10import Control.Applicative ((<$>))
11import Text.ParserCombinators.Parsec 11import 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
16data 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
27quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"') 14quotedChar = noneOf ['\"'] <|> try (string "\\\"" >> return '"')
28 15
@@ -92,7 +79,6 @@ parseQuote = parseModifier "'" "quote"
92parseQuasiquote = parseModifier "`" "quasiquote" 79parseQuasiquote = parseModifier "`" "quasiquote"
93parseUnquote = parseModifier "," "unquote" 80parseUnquote = parseModifier "," "unquote"
94parseUnquoteSplicing = parseModifier ",@" "unquote-splicing" 81parseUnquoteSplicing = parseModifier ",@" "unquote-splicing"
95-- TODO: add modifier for unquote splicing: ,@
96 82
97parseLispValue :: Parser Expr 83parseLispValue :: Parser Expr
98parseLispValue = 84parseLispValue =
@@ -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
117showLispList :: [Expr] -> String
118showLispList = unwords . map show
119
120instance 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