mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-08 10:20:41 +00:00
parent
4b4f38ad31
commit
c9cc12e922
@ -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 '.':
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user