Suggest end of input in some error messages

see #15
This commit is contained in:
Arne Keller 2021-08-08 17:16:16 +02:00
parent 2817d9009f
commit e6d00f4561
3 changed files with 29 additions and 8 deletions

View File

@ -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 '.':

View File

@ -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)));
}
}
}

View File

@ -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<String, ParseError> entry : tests.entrySet()) {
TypeAssumptionParser parser = new TypeAssumptionParser();
Result<Map<VarTerm, TypeAbstraction>, ParseError> type = parser.parse("type1:" + entry.getKey());
@ -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();
}