mirror of
https://gitlab.kit.edu/uskyk/typicalc.git
synced 2024-11-12 20:23:52 +00:00
Attach character + position to some errors
This commit is contained in:
parent
a176d299ce
commit
251d7a3fc2
@ -29,11 +29,6 @@
|
|||||||
bottom: 2.1em;
|
bottom: 2.1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.help-field {
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
kbd {
|
kbd {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
@ -46,4 +41,4 @@ kbd {
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
padding: 2px 4px;
|
padding: 2px 4px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
@ -82,15 +82,20 @@ public class LambdaLexer {
|
|||||||
char c = term.charAt(pos);
|
char c = term.charAt(pos);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '-':
|
case '-':
|
||||||
if (pos + 1 < term.length() && term.charAt(pos + 1) == '>') {
|
if (pos + 1 < term.length()) {
|
||||||
t = new Token(TokenType.ARROW, "->", pos);
|
if (term.charAt(pos + 1) == '>') {
|
||||||
advance();
|
t = new Token(TokenType.ARROW, "->", pos);
|
||||||
advance();
|
advance();
|
||||||
return new Result<>(t);
|
advance();
|
||||||
|
return new Result<>(t);
|
||||||
|
} else {
|
||||||
|
return new Result<>(null, ParseError.UNEXPECTED_CHARACTER
|
||||||
|
.withCharacter(term.charAt(pos + 1), pos + 1));
|
||||||
|
}
|
||||||
} else {
|
} 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 '.':
|
case '.':
|
||||||
t = new Token(TokenType.DOT, ".", pos);
|
t = new Token(TokenType.DOT, ".", pos);
|
||||||
advance();
|
advance();
|
||||||
@ -124,7 +129,8 @@ public class LambdaLexer {
|
|||||||
} while (pos < term.length() && Character.isLetterOrDigit(term.charAt(pos))
|
} while (pos < term.length() && Character.isLetterOrDigit(term.charAt(pos))
|
||||||
&& (int) term.charAt(pos) < 128);
|
&& (int) term.charAt(pos) < 128);
|
||||||
if (pos < term.length() && (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();
|
String s = sb.toString();
|
||||||
TokenType type;
|
TokenType type;
|
||||||
@ -156,7 +162,7 @@ public class LambdaLexer {
|
|||||||
} while (pos < term.length() && Character.isDigit(term.charAt(pos)));
|
} while (pos < term.length() && Character.isDigit(term.charAt(pos)));
|
||||||
return new Result<>(new Token(TokenType.NUMBER, sb.toString(), startPos));
|
return new Result<>(new Token(TokenType.NUMBER, sb.toString(), startPos));
|
||||||
} else {
|
} else {
|
||||||
return new Result<>(null, ParseError.UNEXPECTED_CHARACTER);
|
return new Result<>(null, ParseError.UNEXPECTED_CHARACTER.withCharacter(c, pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ public enum ParseError {
|
|||||||
UNEXPECTED_CHARACTER;
|
UNEXPECTED_CHARACTER;
|
||||||
|
|
||||||
private Token cause = new Token(Token.TokenType.EOF, "", -1);
|
private Token cause = new Token(Token.TokenType.EOF, "", -1);
|
||||||
|
private char wrongChar = '\0';
|
||||||
|
private int position = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach a token to this error.
|
* Attach a token to this error.
|
||||||
@ -36,6 +38,19 @@ public enum ParseError {
|
|||||||
return this;
|
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
|
* @return the token associated with this error, or null if none
|
||||||
*/
|
*/
|
||||||
@ -43,6 +58,14 @@ public enum ParseError {
|
|||||||
return cause;
|
return cause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public char getWrongCharacter() {
|
||||||
|
return wrongChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
ParseError() {
|
ParseError() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,14 @@ public class ErrorView extends VerticalLayout implements LocaleChangeObserver {
|
|||||||
|
|
||||||
if (error == ParseError.TOO_FEW_TOKENS) {
|
if (error == ParseError.TOO_FEW_TOKENS) {
|
||||||
additionalInformation.add(new Span(getTranslation("root.tooFewTokensHelp")));
|
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 {
|
} else {
|
||||||
if (error.getCause().getPos() == NO_ADDITIONAL_INFO) {
|
if (error.getCause().getPos() == NO_ADDITIONAL_INFO) {
|
||||||
return summary;
|
return summary;
|
||||||
|
@ -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}.
|
* These panels are used for the Accordion in the {@link edu.kit.typicalc.view.main.HelpDialog}.
|
||||||
*/
|
*/
|
||||||
public class HelpContentField extends AccordionPanel implements LocaleChangeObserver {
|
public class HelpContentField extends AccordionPanel implements LocaleChangeObserver {
|
||||||
private static final String CLASSNAME = "help-field";
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -2793005857762897734L;
|
private static final long serialVersionUID = -2793005857762897734L;
|
||||||
|
|
||||||
private final String summaryKey;
|
private final String summaryKey;
|
||||||
|
@ -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. \
|
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 \
|
Zusätzlich dazu enthält der Dialog einen Permalink zur aktuellen Seite, der sowohl den Term als auch die Typannahmen \
|
||||||
kodiert.
|
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.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_TOKEN=Die Eingabe 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_CHARACTER=Die Eingabe enhält ein Zeichen, welches an dieser Stelle nicht erlaubt ist!
|
||||||
error.heading=Syntaktisch falsche Eingabe!
|
error.heading=Syntaktisch falsche Eingabe!
|
||||||
root.wrongCharacter=Falsches Zeichen: \u0020
|
root.wrongCharacter=Falsches Zeichen: \u0020
|
||||||
root.position=An Position: \u0020
|
root.position=An Position: \u0020
|
||||||
|
Loading…
Reference in New Issue
Block a user