001package org.clafer.frontend;
002
003
004/**
005 * A token: its kind, its text exactly as written, and where it is.
006 *
007 * @param kind the kind
008 * @param text the source text of the token
009 * @param span where the token is
010 */
011public record Token(TokenKind kind, String text, SourceSpan span) {
012
013    /**
014     * @param symbol an operator or punctuation
015     * @return whether this token is that symbol
016     */
017    public boolean isSymbol(String symbol) {
018        return kind == TokenKind.SYMBOL && text.equals(symbol);
019    }
020
021    /**
022     * @param word a keyword or name
023     * @return whether this token is that word
024     */
025    public boolean isWord(String word) {
026        return kind == TokenKind.WORD && text.equals(word);
027    }
028
029    @Override
030    public String toString() {
031        return kind + " " + text + " at " + span;
032    }
033}