diff --git a/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java b/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java index 52aecc5..5290e5d 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java +++ b/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java @@ -93,7 +93,9 @@ public class LambdaLexer { .withCharacter(term.charAt(pos + 1), pos + 1, term, ParseError.ErrorType.TERM_ERROR)); } } else { - return new Result<>(null, ParseError.TOO_FEW_TOKENS); // actually too few *characters* .. + return new Result<>(null, + ParseError.UNEXPECTED_CHARACTER + .withCharacter(' ', term.length(), term, ParseError.ErrorType.TERM_ERROR)); } // bunch of single-character tokens case '.': diff --git a/src/main/java/edu/kit/typicalc/model/parser/LambdaParser.java b/src/main/java/edu/kit/typicalc/model/parser/LambdaParser.java index f1c9c5d..8fae372 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/LambdaParser.java +++ b/src/main/java/edu/kit/typicalc/model/parser/LambdaParser.java @@ -91,7 +91,7 @@ public class LambdaParser { return t; } return new Result<>(null, - (last.getType() == TokenType.EOF ? ParseError.TOO_FEW_TOKENS : ParseError.UNEXPECTED_TOKEN) + ParseError.UNEXPECTED_TOKEN .withToken(last, ParseError.ErrorType.TERM_ERROR) .expectedTypes(ATOM_START_TOKENS)); } @@ -109,7 +109,9 @@ public class LambdaParser { } } if (token.getType() == TokenType.EOF) { - return new Result<>(null, ParseError.TOO_FEW_TOKENS); + return new Result<>(null, ParseError.UNEXPECTED_TOKEN + .withToken(token, ParseError.ErrorType.TERM_ERROR) + .expectedInput(ExpectedInput.TERM)); } return parseApplication(); } diff --git a/src/main/java/edu/kit/typicalc/model/parser/ParseError.java b/src/main/java/edu/kit/typicalc/model/parser/ParseError.java index 721fd30..3a4c3af 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/ParseError.java +++ b/src/main/java/edu/kit/typicalc/model/parser/ParseError.java @@ -17,14 +17,6 @@ public enum ParseError { */ UNEXPECTED_TOKEN, - /** - * some tokens were required, but not provided - * - * DEPRECATED: use UNEXPECTED_TOKEN with TokenType.EOF instead - */ - @Deprecated - TOO_FEW_TOKENS, - /** * the string contained a character not allowed in that context */ diff --git a/src/test/java/edu/kit/typicalc/model/parser/LambdaParserTest.java b/src/test/java/edu/kit/typicalc/model/parser/LambdaParserTest.java index f8aca8c..b5ae408 100644 --- a/src/test/java/edu/kit/typicalc/model/parser/LambdaParserTest.java +++ b/src/test/java/edu/kit/typicalc/model/parser/LambdaParserTest.java @@ -91,13 +91,21 @@ class LambdaParserTest { term.unwrap() ); } + @Test void errorHandling() { LambdaParser parser = new LambdaParser(""); - assertEquals(ParseError.TOO_FEW_TOKENS, parser.parse().unwrapError()); - parser = new LambdaParser("x)"); ParseError error = parser.parse().unwrapError(); assertEquals(ParseError.UNEXPECTED_TOKEN, error); + assertEquals(TokenType.EOF, error.getCause().get().getType()); + parser = new LambdaParser("λx."); + error = parser.parse().unwrapError(); + assertEquals(ParseError.UNEXPECTED_TOKEN, error); + assertEquals(new Token(TokenType.EOF, "", "λx.", 3), error.getCause().get()); + assertEquals(ExpectedInput.TERM, error.getExpectedInput().get()); + parser = new LambdaParser("x)"); + error = parser.parse().unwrapError(); + assertEquals(ParseError.UNEXPECTED_TOKEN, error); assertEquals(new Token(TokenType.RIGHT_PARENTHESIS, ")", "x)", 1), error.getCause().get()); parser = new LambdaParser("??"); assertEquals(ParseError.UNEXPECTED_CHARACTER, parser.parse().unwrapError());