diff --git a/frontend/styles/view/main/help-dialog.css b/frontend/styles/view/main/help-dialog.css index d9e7379..1b05a66 100644 --- a/frontend/styles/view/main/help-dialog.css +++ b/frontend/styles/view/main/help-dialog.css @@ -29,11 +29,6 @@ bottom: 2.1em; } -.help-field { - justify-content: center; - align-items: center; -} - kbd { background-color: #eee; border-radius: 3px; @@ -46,4 +41,4 @@ kbd { line-height: 1; padding: 2px 4px; white-space: nowrap; -} \ No newline at end of file +} diff --git a/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java b/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java index 12f3bff..1e7d721 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java +++ b/src/main/java/edu/kit/typicalc/model/parser/LambdaLexer.java @@ -82,15 +82,20 @@ public class LambdaLexer { char c = term.charAt(pos); switch (c) { case '-': - if (pos + 1 < term.length() && term.charAt(pos + 1) == '>') { - t = new Token(TokenType.ARROW, "->", pos); - advance(); - advance(); - return new Result<>(t); + if (pos + 1 < term.length()) { + if (term.charAt(pos + 1) == '>') { + t = new Token(TokenType.ARROW, "->", pos); + advance(); + advance(); + return new Result<>(t); + } else { + return new Result<>(null, ParseError.UNEXPECTED_CHARACTER + .withCharacter(term.charAt(pos + 1), pos + 1)); + } } else { - return new Result<>(null, ParseError.UNEXPECTED_CHARACTER); + return new Result<>(null, ParseError.TOO_FEW_TOKENS); // actually too few *characters* .. } - // bunch of single-character tokens + // bunch of single-character tokens case '.': t = new Token(TokenType.DOT, ".", pos); advance(); @@ -124,7 +129,8 @@ public class LambdaLexer { } while (pos < term.length() && Character.isLetterOrDigit(term.charAt(pos)) && (int) term.charAt(pos) < 128); if (pos < term.length() && (int) term.charAt(pos) >= 128) { - return new Result<>(null, ParseError.UNEXPECTED_CHARACTER); + return new Result<>(null, ParseError.UNEXPECTED_CHARACTER + .withCharacter(term.charAt(pos), pos)); } String s = sb.toString(); TokenType type; @@ -156,7 +162,7 @@ public class LambdaLexer { } while (pos < term.length() && Character.isDigit(term.charAt(pos))); return new Result<>(new Token(TokenType.NUMBER, sb.toString(), startPos)); } else { - return new Result<>(null, ParseError.UNEXPECTED_CHARACTER); + return new Result<>(null, ParseError.UNEXPECTED_CHARACTER.withCharacter(c, pos)); } } } 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 478bf35..0beba53 100644 --- a/src/main/java/edu/kit/typicalc/model/parser/ParseError.java +++ b/src/main/java/edu/kit/typicalc/model/parser/ParseError.java @@ -24,6 +24,8 @@ public enum ParseError { UNEXPECTED_CHARACTER; private Token cause = new Token(Token.TokenType.EOF, "", -1); + private char wrongChar = '\0'; + private int position = -1; /** * Attach a token to this error. @@ -36,6 +38,19 @@ public enum ParseError { return this; } + /** + * Attach a character and position to this error. + * + * @param cause the character + * @param position it's position + * @return this object + */ + public ParseError withCharacter(char cause, int position) { + this.wrongChar = cause; + this.position = position; + return this; + } + /** * @return the token associated with this error, or null if none */ @@ -43,6 +58,14 @@ public enum ParseError { return cause; } + public char getWrongCharacter() { + return wrongChar; + } + + public int getPosition() { + return position; + } + ParseError() { } 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 f10c15a..ca74211 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 @@ -46,6 +46,14 @@ public class ErrorView extends VerticalLayout implements LocaleChangeObserver { if (error == ParseError.TOO_FEW_TOKENS) { additionalInformation.add(new Span(getTranslation("root.tooFewTokensHelp"))); + } else if (error == ParseError.UNEXPECTED_CHARACTER) { + char c = error.getWrongCharacter(); + if (c != '\0') { + additionalInformation.add(new Span(getTranslation("root.wrongCharacter") + c)); + additionalInformation.add(new Span(getTranslation("root.position") + error.getPosition())); + } else { + return summary; + } } else { if (error.getCause().getPos() == NO_ADDITIONAL_INFO) { return summary; diff --git a/src/main/java/edu/kit/typicalc/view/main/HelpContentField.java b/src/main/java/edu/kit/typicalc/view/main/HelpContentField.java index 8a843b2..136eb5c 100644 --- a/src/main/java/edu/kit/typicalc/view/main/HelpContentField.java +++ b/src/main/java/edu/kit/typicalc/view/main/HelpContentField.java @@ -15,8 +15,6 @@ import com.vaadin.flow.i18n.LocaleChangeObserver; * These panels are used for the Accordion in the {@link edu.kit.typicalc.view.main.HelpDialog}. */ public class HelpContentField extends AccordionPanel implements LocaleChangeObserver { - private static final String CLASSNAME = "help-field"; - private static final long serialVersionUID = -2793005857762897734L; private final String summaryKey; diff --git a/src/main/resources/language/translation_de.properties b/src/main/resources/language/translation_de.properties index 568475f..af01555 100644 --- a/src/main/resources/language/translation_de.properties +++ b/src/main/resources/language/translation_de.properties @@ -75,10 +75,10 @@ root.helpShareButton=Durch Benutzen des Teilen-Knopfs öffnet sich ein Dialog, i Typherleitungsbaums des eingegebenen Terms und die benötigen Pakete zum Einbinden des LaTeX-Codes angezeigt werden. \ Zusätzlich dazu enthält der Dialog einen Permalink zur aktuellen Seite, der sowohl den Term als auch die Typannahmen \ kodiert. -root.TOO_FEW_TOKENS=Falsche Eingabe! Der Term endet abrupt. +root.TOO_FEW_TOKENS=Falsche Eingabe! Die Eingabe endet abrupt. root.tooFewTokensHelp=Überprüfe, ob alle Let-, Abs- und App-Terme über die nötigen Argumente verfügen. -root.UNEXPECTED_TOKEN=Der Term entspricht nicht der im Info-Dialog spezifizierten Syntax! -root.UNEXPECTED_CHARACTER=Der Term enhält ein Zeichen, welches an dieser Stelle nicht erlaubt ist! +root.UNEXPECTED_TOKEN=Die Eingabe entspricht nicht der im Info-Dialog spezifizierten Syntax! +root.UNEXPECTED_CHARACTER=Die Eingabe enhält ein Zeichen, welches an dieser Stelle nicht erlaubt ist! error.heading=Syntaktisch falsche Eingabe! root.wrongCharacter=Falsches Zeichen: \u0020 root.position=An Position: \u0020