diff --git a/src/ExprParser.hs b/src/ExprParser.hs index 061b41c..da4599e 100644 --- a/src/ExprParser.hs +++ b/src/ExprParser.hs @@ -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 diff --git a/src/TokenParser.hs b/src/TokenParser.hs index 3e1afd7..8900e6d 100644 --- a/src/TokenParser.hs +++ b/src/TokenParser.hs @@ -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