From 878130ebba32aa3831373c7e69a2fed9b079cbe0 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Fri, 29 Jan 2021 08:12:45 +0100 Subject: [PATCH] Handle empty lambda term in parser --- pom.xml | 2 +- .../java/edu/kit/typicalc/model/parser/LambdaParser.java | 2 ++ src/main/java/edu/kit/typicalc/model/parser/ParseError.java | 5 +++++ .../java/edu/kit/typicalc/model/parser/LambdaParserTest.java | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a59e510..65684a2 100644 --- a/pom.xml +++ b/pom.xml @@ -184,7 +184,7 @@ checkstyle - validate + test check 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 8672467..b0642d9 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/LambdaParser.java +++ b/src/main/java/edu/kit/typicalc/model/parser/LambdaParser.java @@ -88,6 +88,8 @@ public class LambdaParser { case LET: Result let = parseLet(); return new Result<>(let.unwrap(), let.getError()); + case EOF: + return new Result<>(null, ParseError.TOO_FEW_TOKENS); default: return parseApplication(); } diff --git a/src/main/java/edu/kit/typicalc/model/parser/ParseError.java b/src/main/java/edu/kit/typicalc/model/parser/ParseError.java index 4b11451..dc0f6bb 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/ParseError.java +++ b/src/main/java/edu/kit/typicalc/model/parser/ParseError.java @@ -12,6 +12,11 @@ public enum ParseError { */ TOO_MANY_TOKENS, + /** + * some tokens were required, but not provided + */ + TOO_FEW_TOKENS, + /** * the string contained a character not allowed in that context */ 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 dd61151..d920d02 100644 --- a/src/test/java/edu/kit/typicalc/model/parser/LambdaParserTest.java +++ b/src/test/java/edu/kit/typicalc/model/parser/LambdaParserTest.java @@ -77,4 +77,9 @@ class LambdaParserTest { new BooleanTerm(true) )); } + @Test + void miscellaneousTerms() { + LambdaParser parser = new LambdaParser(""); + assertEquals(parser.parse().unwrapError(), ParseError.TOO_FEW_TOKENS); + } }