From 4b4f38ad317472599939a0f7099b01c95182b6de Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Fri, 9 Jul 2021 13:02:19 +0200 Subject: [PATCH] ErrorView: handle unexpected EOF token --- .../typicalc/view/content/errorcontent/ErrorView.java | 11 +++++++---- src/main/resources/language/translation_de.properties | 2 +- src/main/resources/language/translation_en.properties | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/kit/typicalc/view/content/errorcontent/ErrorView.java b/src/main/java/edu/kit/typicalc/view/content/errorcontent/ErrorView.java index 42801b5..b67c8fa 100644 --- a/src/main/java/edu/kit/typicalc/view/content/errorcontent/ErrorView.java +++ b/src/main/java/edu/kit/typicalc/view/content/errorcontent/ErrorView.java @@ -65,16 +65,19 @@ public class ErrorView extends VerticalLayout implements LocaleChangeObserver { descriptionForError = "error"; } switch (error) { - case TOO_FEW_TOKENS: - additionalInformation.add(new Span(getTranslation("error.tooFewTokensHelp"))); - break; case UNEXPECTED_TOKEN: Optional cause = error.getCause(); if (cause.isPresent()) { + String errorText; + if (cause.get().getType() != Token.TokenType.EOF) { + errorText = getTranslation("error.wrongCharacter") + cause.get().getText(); + } else { + errorText = getTranslation("error.tooFewTokensHelp"); + } additionalInformation.add(new Span(new Pre(getTranslation(descriptionForError) + term + "\n" + " ".repeat(Math.max(getTranslation(descriptionForError).length(), cause.get().getPos() + getTranslation(descriptionForError).length())) - + "^ " + getTranslation("error.wrongCharacter") + cause.get().getText()))); + + "^ " + errorText))); } break; case UNEXPECTED_CHARACTER: diff --git a/src/main/resources/language/translation_de.properties b/src/main/resources/language/translation_de.properties index d8b4c79..4d95ccc 100644 --- a/src/main/resources/language/translation_de.properties +++ b/src/main/resources/language/translation_de.properties @@ -103,7 +103,7 @@ help.typicalcInfo=\ Johanna Stuber
root.TOO_FEW_TOKENS=Falsche Eingabe! Die Eingabe endet abrupt. -error.tooFewTokensHelp=Überprüfe, ob alle Let-, Abs- und App-Terme über die nötigen Argumente verfügen. +error.tooFewTokensHelp=unerwartetes Ende der Eingabe root.UNEXPECTED_TOKEN=Die Eingabe entspricht nicht der im Info-Dialog spezifizierten Syntax! root.UNEXPECTED_CHARACTER=Die Eingabe enthält ein Zeichen, welches an dieser Stelle nicht erlaubt ist! error.heading=Syntaktisch falsche Eingabe! diff --git a/src/main/resources/language/translation_en.properties b/src/main/resources/language/translation_en.properties index 4778fc8..e55f166 100644 --- a/src/main/resources/language/translation_en.properties +++ b/src/main/resources/language/translation_en.properties @@ -95,7 +95,7 @@ help.typicalcInfo=\ Johanna Stuber root.TOO_FEW_TOKENS=Wrong input! The term ends abruptly. -error.tooFewTokensHelp=Check if all let, abstraction and application terms consist of the required arguments. +error.tooFewTokensHelp=unexpected end of input root.UNEXPECTED_TOKEN=The input does not match the syntax specified in the info dialog. root.UNEXPECTED_CHARACTER=The input contains a character which is not allowed at this position. error.heading=Input is syntactically wrong!