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

org.watertemplate.interpreter.parser.Token Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package org.watertemplate.interpreter.parser;

import java.util.Collections;
import java.util.List;

public class Token {
    static final Token END_OF_INPUT = new Token("\0", Terminal.END_OF_INPUT);

    private final String value;
    private final List possibleTerminals;

    Token(final String value, final Terminal possibleTerminals) {
        this.possibleTerminals = Collections.singletonList(possibleTerminals);
        this.value = value;
    }

    Token(final String value, final List possibleTerminals) {
        this.possibleTerminals = possibleTerminals;
        this.value = value;
    }

    String getValue() {
        return value;
    }

    boolean canBe(final Terminal terminal) {
        return possibleTerminals.contains(terminal);
    }

    @Override
    public String toString() {
        return "[" + possibleTerminals.stream().map(Enum::toString).reduce((a, b) -> a + "|" + b).get() + "] -> [" + value + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy