Fix syntax error return in parenthesised term

part of #9
This commit is contained in:
Arne Keller 2021-07-10 12:17:47 +02:00
parent 7d4c724338
commit 2715179182
2 changed files with 13 additions and 0 deletions

View File

@ -224,6 +224,9 @@ public class LambdaParser {
return new Result<>(null, error.get().expectedInput(ExpectedInput.TERM)); return new Result<>(null, error.get().expectedInput(ExpectedInput.TERM));
} }
Result<LambdaTerm, ParseError> term = parseTerm(false); Result<LambdaTerm, ParseError> term = parseTerm(false);
if (term.isError()) {
return term; // return error early
}
error = expect(TokenType.RIGHT_PARENTHESIS); error = expect(TokenType.RIGHT_PARENTHESIS);
if (error.isEmpty()) { if (error.isEmpty()) {
return term; return term;

View File

@ -7,6 +7,7 @@ import nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class LambdaParserTest { class LambdaParserTest {
private static final VarTerm X = new VarTerm("x"); private static final VarTerm X = new VarTerm("x");
@ -202,6 +203,15 @@ class LambdaParserTest {
assertEquals(3, error.getPosition()); assertEquals(3, error.getPosition());
} }
@Test
void errorCase1() {
LambdaParser parser = new LambdaParser("(λx.x)(λ");
ParseError error = parser.parse().unwrapError();
assertEquals(TokenType.EOF, error.getCause().get().getType());
assertEquals(1, error.getExpected().get().size());
assertTrue(error.getExpected().get().contains(TokenType.VARIABLE));
}
@Test @Test
void equality() { void equality() {
EqualsVerifier.forClass(Token.class).usingGetClass().verify(); EqualsVerifier.forClass(Token.class).usingGetClass().verify();