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 :: String -> Either ParseError Expr
|
||||||
parseExpression s = do
|
parseExpression s = do
|
||||||
tokns <- parse parseTokens "lexical error" s
|
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
|
return expr
|
||||||
|
|
||||||
expressionFromTokens :: GenParser Token st Expr
|
expressionFromTokens :: GenParser Token st Expr
|
||||||
expressionFromTokens = do
|
expressionFromTokens = do
|
||||||
expr <- intE <|> try defineE <|> try nilE <|> varE <|> procedureE
|
expr <- intE <|> try defineE <|> try nilE <|> varE <|> procedureE
|
||||||
_ <- eof
|
|
||||||
return expr
|
return expr
|
||||||
|
|
||||||
intE :: GenParser Token st Expr
|
intE :: GenParser Token st Expr
|
||||||
|
|
|
@ -8,7 +8,9 @@ import TokenType
|
||||||
parseTokens :: GenParser Char st [Token]
|
parseTokens :: GenParser Char st [Token]
|
||||||
parseTokens = do
|
parseTokens = do
|
||||||
_ <- spaces
|
_ <- spaces
|
||||||
many $ (spaces >> anyLispToken)
|
tokns <- many $ do t <- anyLispToken; spaces; return t
|
||||||
|
_ <- eof
|
||||||
|
return tokns
|
||||||
|
|
||||||
anyLispToken :: GenParser Char st Token
|
anyLispToken :: GenParser Char st Token
|
||||||
anyLispToken = leftParenT <|> rightParenT <|> try nilT <|> try defineT <|> varT <|> intT
|
anyLispToken = leftParenT <|> rightParenT <|> try nilT <|> try defineT <|> varT <|> intT
|
||||||
|
|
Loading…
Reference in New Issue