Fixes. Now the parsing is correct
This commit is contained in:
parent
fd39ca4129
commit
132b3972a0
|
@ -9,13 +9,18 @@ import ExprType
|
|||
parseExpression :: String -> Either ParseError Expr
|
||||
parseExpression s = do
|
||||
tokns <- parse parseTokens "lexical error" s
|
||||
expr <- parse expressionFromTokens "parsing error" tokns
|
||||
expr <- parse expressionFromTokensEOF "parsing error" tokns
|
||||
return expr
|
||||
|
||||
expressionFromTokensEOF :: GenParser Token st Expr
|
||||
expressionFromTokensEOF = do
|
||||
expr <- expressionFromTokens
|
||||
_ <- eof
|
||||
return expr
|
||||
|
||||
expressionFromTokens :: GenParser Token st Expr
|
||||
expressionFromTokens = do
|
||||
expr <- intE <|> try defineE <|> try nilE <|> varE <|> procedureE
|
||||
_ <- eof
|
||||
return expr
|
||||
|
||||
intE :: GenParser Token st Expr
|
||||
|
|
|
@ -8,7 +8,9 @@ import TokenType
|
|||
parseTokens :: GenParser Char st [Token]
|
||||
parseTokens = do
|
||||
_ <- spaces
|
||||
many $ (spaces >> anyLispToken)
|
||||
tokns <- many $ do t <- anyLispToken; spaces; return t
|
||||
_ <- eof
|
||||
return tokns
|
||||
|
||||
anyLispToken :: GenParser Char st Token
|
||||
anyLispToken = leftParenT <|> rightParenT <|> try nilT <|> try defineT <|> varT <|> intT
|
||||
|
|
Loading…
Reference in New Issue