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 8fae372..aca2f8b 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/LambdaParser.java +++ b/src/main/java/edu/kit/typicalc/model/parser/LambdaParser.java @@ -224,6 +224,9 @@ public class LambdaParser { return new Result<>(null, error.get().expectedInput(ExpectedInput.TERM)); } Result term = parseTerm(false); + if (term.isError()) { + return term; // return error early + } error = expect(TokenType.RIGHT_PARENTHESIS); if (error.isEmpty()) { return term; 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 b5ae408..627ebc3 100644 --- a/src/test/java/edu/kit/typicalc/model/parser/LambdaParserTest.java +++ b/src/test/java/edu/kit/typicalc/model/parser/LambdaParserTest.java @@ -7,6 +7,7 @@ import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class LambdaParserTest { private static final VarTerm X = new VarTerm("x"); @@ -202,6 +203,15 @@ class LambdaParserTest { 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 void equality() { EqualsVerifier.forClass(Token.class).usingGetClass().verify();