From 08085ad44d0a803909e5cfa44df55ccb918b8c74 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Mon, 19 Jul 2021 11:12:58 +0200 Subject: [PATCH] Fix parse error for "s:()" see #15 --- .../typicalc/model/parser/TypeAssumptionParser.java | 6 +++++- .../model/parser/TypeAssumptionParserTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java index 92d52e6..33cb5d2 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java +++ b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java @@ -331,7 +331,11 @@ public class TypeAssumptionParser { ParserResult result = handleInnerParenthesis( new Token(TokenType.EOF, "", "", -1)); if (result.isError()) { - return result.castError(); + return result + // replace dummy EOF token + .modifyError(err -> + err.withToken(t, ParseError.ErrorType.TYPE_ASSUMPTION_ERROR)) + .castError(); } else { parsedType = Optional.of(result.getResult()); stateParenthesis = Optional.empty(); diff --git a/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java b/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java index ac6d6ca..74243a5 100644 --- a/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java +++ b/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java @@ -359,6 +359,16 @@ class TypeAssumptionParserTest { e); } + @Test + void errorCase4() { + ParseError e = parse("s:()"); + assertEquals(ParseError + .unexpectedToken(new Token(Token.TokenType.RIGHT_PARENTHESIS, ")", "s:()", 3), + ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) + .expectedInput(ExpectedInput.TYPE), + e); + } + static ParseError parse(String input) { return new TypeAssumptionParser().parse(input).unwrapError(); }