simplegrammar.UnexpectedTokenException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simple-grammar Show documentation
Show all versions of simple-grammar Show documentation
Library is used to define LL* grammars and use them to parse text data, e. g. programming
languages or data in different formats like JSON or XML
The newest version!
package simplegrammar;
public class UnexpectedTokenException extends ParseException {
private static String formatMessage(Token token) {
StringBuilder messageBuilder = new StringBuilder()
.append("Unexpected ")
.append(token.getName());
if (token.getValue() != null)
messageBuilder
.append(" \"")
.append(token.getValue())
.append("\"");
if (token.getLine() != null) {
messageBuilder
.append(" at line ")
.append(token.getLine());
if (token.getPosition() != null)
messageBuilder
.append(", position ")
.append(token.getPosition());
}
return messageBuilder.append('!').toString();
}
private final Token token;
public UnexpectedTokenException(Token token) {
super(formatMessage(token));
this.token = token;
}
public Token getToken() {
return token;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy