From 5e6cb6ca4cfbefd5429650753381cd59d66494c6 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Mon, 19 Jul 2021 11:06:56 +0200 Subject: [PATCH] Generate useful error for TA input "s" see #15 --- .../typicalc/model/parser/TypeAssumptionParser.java | 4 +++- .../model/parser/TypeAssumptionParserTest.java | 10 ++++++++++ 2 files changed, 13 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 9e13215..92d52e6 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java +++ b/src/main/java/edu/kit/typicalc/model/parser/TypeAssumptionParser.java @@ -172,7 +172,9 @@ public class TypeAssumptionParser { if (t.getType() == TokenType.COLON) { return new ParserResult<>(new ExpectingTypeDef(alreadyParsed, var)); } else { - return new ParserResult<>(ParseError.unexpectedToken(t, ParseError.ErrorType.TYPE_ASSUMPTION_ERROR)); + return new ParserResult<>(ParseError + .unexpectedToken(t, ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) + .expectedType(TokenType.COLON)); } } } 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 e7e88ca..ac6d6ca 100644 --- a/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java +++ b/src/test/java/edu/kit/typicalc/model/parser/TypeAssumptionParserTest.java @@ -349,6 +349,16 @@ class TypeAssumptionParserTest { assertEquals(Token.TokenType.EOF, e.getCause().get().getType()); } + @Test + void errorCase3() { + ParseError e = parse("s"); + assertEquals(ParseError + .unexpectedToken(new Token(Token.TokenType.EOF, "", "s", 1), + ParseError.ErrorType.TYPE_ASSUMPTION_ERROR) + .expectedType(Token.TokenType.COLON), + e); + } + static ParseError parse(String input) { return new TypeAssumptionParser().parse(input).unwrapError(); }