All Downloads are FREE. Search and download functionalities are using the official Maven repository.

simplegrammar.UnexpectedTokenException Maven / Gradle / Ivy

Go to download

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