ErrorView: handle unexpected EOF token

This commit is contained in:
Arne Keller 2021-07-09 13:02:19 +02:00
parent f87a6820cc
commit 4b4f38ad31
3 changed files with 9 additions and 6 deletions

View File

@ -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<Token> 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:

View File

@ -103,7 +103,7 @@ help.typicalcInfo=\
Johanna Stuber<br>
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!

View File

@ -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!