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 2b45a47..04729c6 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java +++ b/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java @@ -92,11 +92,12 @@ public class LambdaLexer { return new Result<>(t); } else { return new Result<>(null, ParseError.unexpectedCharacter2( - term.charAt(pos + 1), pos + 1, term, errorType)); + term.charAt(pos + 1), pos + 1, term, errorType).expectedCharacter('>')); } } else { return new Result<>(null, - ParseError.unexpectedCharacter2(' ', term.length(), term, errorType)); + ParseError.unexpectedCharacter2(' ', term.length(), term, errorType) + .expectedCharacter('>')); } // bunch of single-character tokens case '.': diff --git a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java index fda5193..701d472 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java +++ b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java @@ -78,7 +78,8 @@ public class TypeAssumptionParser { typeVariableUniqueIndex++; if (currentToken.getType() != Token.TokenType.COMMA) { return new Result<>(null, ParseError.unexpectedToken(currentToken, - ParseError.ErrorType.TYPE_ASSUMPTION_ERROR).expectedType(Token.TokenType.COMMA)); + ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) + .expectedTypes(List.of(Token.TokenType.COMMA, Token.TokenType.EOF))); } } } diff --git a/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java b/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java index 4a78cd4..3880569 100644 --- a/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java +++ b/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java @@ -281,10 +281,10 @@ class TypeAssumptionParserTest { .expectedType(Token.TokenType.ARROW)); tests.put("x )", ParseError.unexpectedToken(new Token(Token.TokenType.RIGHT_PARENTHESIS, ")", "type1:x )", 8), ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) - .expectedType(Token.TokenType.COMMA)); + .expectedTypes(List.of(Token.TokenType.COMMA, Token.TokenType.EOF))); tests.put("x -> (x) )", ParseError.unexpectedToken(new Token(Token.TokenType.RIGHT_PARENTHESIS, ")", "type1:x -> (x) )", 15), ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) - .expectedType(Token.TokenType.COMMA)); + .expectedTypes(List.of(Token.TokenType.COMMA, Token.TokenType.EOF))); for (Map.Entry entry : tests.entrySet()) { TypeAssumptionParser parser = new TypeAssumptionParser(); Result, ParseError> type = parser.parse("type1:" + entry.getKey()); @@ -355,9 +355,9 @@ class TypeAssumptionParserTest { void errorCase3() { ParseError e = parse("s"); assertEquals(ParseError - .unexpectedToken(new Token(Token.TokenType.EOF, "", "s", 1), - ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) - .expectedType(Token.TokenType.COLON), + .unexpectedToken(new Token(Token.TokenType.EOF, "", "s", 1), + ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) + .expectedType(Token.TokenType.COLON), e); } @@ -371,6 +371,25 @@ class TypeAssumptionParserTest { e); } + @Test + void errorCase5() { + ParseError e = parse("g: boolean-"); + assertEquals(ParseError + .unexpectedCharacter2(' ', 11, "g: boolean-", ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) + .expectedCharacter('>'), + e); + } + + @Test + void errorCase6() { + ParseError e = parse("g: boolean:"); + assertEquals(ParseError + .unexpectedToken(new Token(Token.TokenType.COLON, ":", "g: boolean:", 10), + ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) + .expectedTypes(List.of(Token.TokenType.COMMA, Token.TokenType.EOF)), + e); + } + static ParseError parse(String input) { return new TypeAssumptionParser().parse(input).unwrapError(); }