ai.vespa.schemals.parser.yqlplus.Token Maven / Gradle / Ivy
/*
* Generated by: CongoCC Parser Generator. Token.java
*/
package ai.vespa.schemals.parser.yqlplus;
import ai.vespa.schemals.parser.yqlplus.ast.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class Token implements CharSequence, Node.TerminalNode {
public enum TokenType implements Node.NodeType {
EOF, _TOKEN_1, _TOKEN_2, _TOKEN_3, _TOKEN_4, SELECT, LIMIT, OFFSET, WHERE,
ORDER, BY, DESC, ASC, FROM, SOURCES, AS, COMMA, OUTPUT, COUNT, TRUE, FALSE,
LPAREN, RPAREN, LBRACKET, RBRACKET, LBRACE, RBRACE, COLON, PIPE, AND, OR,
NOT_IN, IN, LT, GT, LTEQ, GTEQ, NEQ, STAR, EQ, LIKE, CONTAINS, NOTLIKE, MATCHES,
NOTMATCHES, PLUS, MINUS, DIV, MODULO, EXCLAMATION, NULL, DOT, AT, SQ, DQ,
SEMI, TIMEOUT, ALL, EACH, ORDERBY, IS_NULL, IS_NOT_NULL, IDENTIFIER, LONG_INT,
INT, FLOAT, EXPONENT, LETTER, HEX_DIGIT, UNICODE_ESC, ESC_SEQ, STRING, COMMENT,
DUMMY, INVALID;
public boolean isUndefined() {
return this == DUMMY;
}
public boolean isInvalid() {
return this == INVALID;
}
public boolean isEOF() {
return this == EOF;
}
}
private YQLPlusLexer tokenSource;
private TokenType type = TokenType.DUMMY;
private int beginOffset;
private int endOffset;
private boolean unparsed;
private Node parent;
/**
* It would be extremely rare that an application
* programmer would use this method. It needs to
* be public because it is part of the ai.vespa.schemals.parser.yqlplus.Node interface.
*/
public void setBeginOffset(int beginOffset) {
this.beginOffset = beginOffset;
}
/**
* It would be extremely rare that an application
* programmer would use this method. It needs to
* be public because it is part of the ai.vespa.schemals.parser.yqlplus.Node interface.
*/
public void setEndOffset(int endOffset) {
this.endOffset = endOffset;
}
/**
* @return the YQLPlusLexer object that handles
* location info for the tokens.
*/
public YQLPlusLexer getTokenSource() {
return this.tokenSource;
}
/**
* It should be exceedingly rare that an application
* programmer needs to use this method.
*/
public void setTokenSource(TokenSource tokenSource) {
this.tokenSource = (YQLPlusLexer) tokenSource;
}
public boolean isInvalid() {
return getType().isInvalid();
}
/**
* Return the TokenType of this Token object
*/
@Override
public TokenType getType() {
return type;
}
protected void setType(TokenType type) {
this.type = type;
}
/**
* @return whether this Token represent actual input or was it inserted somehow?
*/
public boolean isVirtual() {
return virtual || type == TokenType.EOF;
}
/**
* @return Did we skip this token in parsing?
*/
public boolean isSkipped() {
return skipped;
}
private boolean virtual;
private boolean skipped;
private boolean dirty;
void setVirtual(boolean virtual) {
this.virtual = virtual;
if (virtual) dirty = true;
}
void setSkipped(boolean skipped) {
this.skipped = skipped;
if (skipped) dirty = true;
}
public boolean isDirty() {
return dirty;
}
public void setDirty(boolean dirty) {
this.dirty = dirty;
}
public int getBeginOffset() {
return beginOffset;
}
public int getEndOffset() {
return endOffset;
}
/**
* @return the string image of the token.
*/
@Override
/**
* @return the next _cached_ regular (i.e. parsed) token
* or null
*/
public final Token getNext() {
return getNextParsedToken();
}
/**
* @return the previous regular (i.e. parsed) token
* or null
*/
public final Token getPrevious() {
Token result = previousCachedToken();
while (result != null && result.isUnparsed()) {
result = result.previousCachedToken();
}
return result;
}
/**
* @return the next regular (i.e. parsed) token
*/
private Token getNextParsedToken() {
Token result = nextCachedToken();
while (result != null && result.isUnparsed()) {
result = result.nextCachedToken();
}
return result;
}
/**
* @return the next token of any sort (parsed or unparsed or invalid)
*/
public Token nextCachedToken() {
if (getType() == TokenType.EOF) return null;
YQLPlusLexer tokenSource = getTokenSource();
return tokenSource != null ? (Token) tokenSource.nextCachedToken(getEndOffset()) : null;
}
public Token previousCachedToken() {
if (getTokenSource() == null) return null;
return (Token) getTokenSource().previousCachedToken(getBeginOffset());
}
Token getPreviousToken() {
return previousCachedToken();
}
public Token replaceType(TokenType type) {
Token result = newToken(type, getTokenSource(), getBeginOffset(), getEndOffset());
getTokenSource().cacheToken(result);
return result;
}
public String getSource() {
if (type == TokenType.EOF) return "";
YQLPlusLexer ts = getTokenSource();
return ts == null ? null : ts.getText(getBeginOffset(), getEndOffset());
}
protected Token() {
}
public Token(TokenType type, YQLPlusLexer tokenSource, int beginOffset, int endOffset) {
this.type = type;
this.tokenSource = tokenSource;
this.beginOffset = beginOffset;
this.endOffset = endOffset;
}
public boolean isUnparsed() {
return unparsed;
}
public void setUnparsed(boolean unparsed) {
this.unparsed = unparsed;
}
/**
* @return An iterator of the tokens preceding this one.
*/
public Iterator precedingTokens() {
return new Iterator() {
Token currentPoint = Token.this;
public boolean hasNext() {
return currentPoint.previousCachedToken() != null;
}
public Token next() {
Token previous = currentPoint.previousCachedToken();
if (previous == null) throw new java.util.NoSuchElementException("No previous token!");
return currentPoint = previous;
}
};
}
/**
* @return a list of the unparsed tokens preceding this one in the order they appear in the input
*/
public List precedingUnparsedTokens() {
List result = new ArrayList<>();
Token t = this.previousCachedToken();
while (t != null && t.isUnparsed()) {
result.add(t);
t = t.previousCachedToken();
}
Collections.reverse(result);
return result;
}
/**
* @return An iterator of the (cached) tokens that follow this one.
*/
public Iterator followingTokens() {
return new java.util.Iterator() {
Token currentPoint = Token.this;
public boolean hasNext() {
return currentPoint.nextCachedToken() != null;
}
public Token next() {
Token next = currentPoint.nextCachedToken();
if (next == null) throw new java.util.NoSuchElementException("No next token!");
return currentPoint = next;
}
};
}
public void copyLocationInfo(Token from) {
setTokenSource(from.getTokenSource());
setBeginOffset(from.getBeginOffset());
setEndOffset(from.getEndOffset());
}
public void copyLocationInfo(Token start, Token end) {
setTokenSource(start.getTokenSource());
if (tokenSource == null) setTokenSource(end.getTokenSource());
setBeginOffset(start.getBeginOffset());
setEndOffset(end.getEndOffset());
}
public static Token newToken(TokenType type, YQLPlusLexer tokenSource, int beginOffset, int endOffset) {
switch(type) {
case ALL :
return new ALL(TokenType.ALL, tokenSource, beginOffset, endOffset);
case LETTER :
return new LETTER(TokenType.LETTER, tokenSource, beginOffset, endOffset);
case UNICODE_ESC :
return new UNICODE_ESC(TokenType.UNICODE_ESC, tokenSource, beginOffset, endOffset);
case LT :
return new LT(TokenType.LT, tokenSource, beginOffset, endOffset);
case FROM :
return new FROM(TokenType.FROM, tokenSource, beginOffset, endOffset);
case PIPE :
return new PIPE(TokenType.PIPE, tokenSource, beginOffset, endOffset);
case DQ :
return new DQ(TokenType.DQ, tokenSource, beginOffset, endOffset);
case DESC :
return new DESC(TokenType.DESC, tokenSource, beginOffset, endOffset);
case MINUS :
return new MINUS(TokenType.MINUS, tokenSource, beginOffset, endOffset);
case LTEQ :
return new LTEQ(TokenType.LTEQ, tokenSource, beginOffset, endOffset);
case LONG_INT :
return new LONG_INT(TokenType.LONG_INT, tokenSource, beginOffset, endOffset);
case EACH :
return new EACH(TokenType.EACH, tokenSource, beginOffset, endOffset);
case NULL :
return new NULL(TokenType.NULL, tokenSource, beginOffset, endOffset);
case OUTPUT :
return new OUTPUT(TokenType.OUTPUT, tokenSource, beginOffset, endOffset);
case IN :
return new IN(TokenType.IN, tokenSource, beginOffset, endOffset);
case LPAREN :
return new LPAREN(TokenType.LPAREN, tokenSource, beginOffset, endOffset);
case MODULO :
return new MODULO(TokenType.MODULO, tokenSource, beginOffset, endOffset);
case DOT :
return new DOT(TokenType.DOT, tokenSource, beginOffset, endOffset);
case TRUE :
return new TRUE(TokenType.TRUE, tokenSource, beginOffset, endOffset);
case RPAREN :
return new RPAREN(TokenType.RPAREN, tokenSource, beginOffset, endOffset);
case NOT_IN :
return new NOT_IN(TokenType.NOT_IN, tokenSource, beginOffset, endOffset);
case WHERE :
return new WHERE(TokenType.WHERE, tokenSource, beginOffset, endOffset);
case EQ :
return new EQ(TokenType.EQ, tokenSource, beginOffset, endOffset);
case AS :
return new AS(TokenType.AS, tokenSource, beginOffset, endOffset);
case AT :
return new AT(TokenType.AT, tokenSource, beginOffset, endOffset);
case RBRACE :
return new RBRACE(TokenType.RBRACE, tokenSource, beginOffset, endOffset);
case LIKE :
return new LIKE(TokenType.LIKE, tokenSource, beginOffset, endOffset);
case AND :
return new AND(TokenType.AND, tokenSource, beginOffset, endOffset);
case COUNT :
return new COUNT(TokenType.COUNT, tokenSource, beginOffset, endOffset);
case TIMEOUT :
return new TIMEOUT(TokenType.TIMEOUT, tokenSource, beginOffset, endOffset);
case LBRACE :
return new LBRACE(TokenType.LBRACE, tokenSource, beginOffset, endOffset);
case PLUS :
return new PLUS(TokenType.PLUS, tokenSource, beginOffset, endOffset);
case IS_NOT_NULL :
return new IS_NOT_NULL(TokenType.IS_NOT_NULL, tokenSource, beginOffset, endOffset);
case FLOAT :
return new FLOAT(TokenType.FLOAT, tokenSource, beginOffset, endOffset);
case SEMI :
return new SEMI(TokenType.SEMI, tokenSource, beginOffset, endOffset);
case LIMIT :
return new LIMIT(TokenType.LIMIT, tokenSource, beginOffset, endOffset);
case NOTMATCHES :
return new NOTMATCHES(TokenType.NOTMATCHES, tokenSource, beginOffset, endOffset);
case CONTAINS :
return new CONTAINS(TokenType.CONTAINS, tokenSource, beginOffset, endOffset);
case INT :
return new INT(TokenType.INT, tokenSource, beginOffset, endOffset);
case COMMENT :
return new COMMENT(TokenType.COMMENT, tokenSource, beginOffset, endOffset);
case SOURCES :
return new SOURCES(TokenType.SOURCES, tokenSource, beginOffset, endOffset);
case ORDER :
return new ORDER(TokenType.ORDER, tokenSource, beginOffset, endOffset);
case ASC :
return new ASC(TokenType.ASC, tokenSource, beginOffset, endOffset);
case IS_NULL :
return new IS_NULL(TokenType.IS_NULL, tokenSource, beginOffset, endOffset);
case BY :
return new BY(TokenType.BY, tokenSource, beginOffset, endOffset);
case HEX_DIGIT :
return new HEX_DIGIT(TokenType.HEX_DIGIT, tokenSource, beginOffset, endOffset);
case OFFSET :
return new OFFSET(TokenType.OFFSET, tokenSource, beginOffset, endOffset);
case ESC_SEQ :
return new ESC_SEQ(TokenType.ESC_SEQ, tokenSource, beginOffset, endOffset);
case IDENTIFIER :
return new IDENTIFIER(TokenType.IDENTIFIER, tokenSource, beginOffset, endOffset);
case ORDERBY :
return new ORDERBY(TokenType.ORDERBY, tokenSource, beginOffset, endOffset);
case SQ :
return new SQ(TokenType.SQ, tokenSource, beginOffset, endOffset);
case COMMA :
return new COMMA(TokenType.COMMA, tokenSource, beginOffset, endOffset);
case OR :
return new OR(TokenType.OR, tokenSource, beginOffset, endOffset);
case LBRACKET :
return new LBRACKET(TokenType.LBRACKET, tokenSource, beginOffset, endOffset);
case RBRACKET :
return new RBRACKET(TokenType.RBRACKET, tokenSource, beginOffset, endOffset);
case COLON :
return new COLON(TokenType.COLON, tokenSource, beginOffset, endOffset);
case GT :
return new GT(TokenType.GT, tokenSource, beginOffset, endOffset);
case SELECT :
return new SELECT(TokenType.SELECT, tokenSource, beginOffset, endOffset);
case DIV :
return new DIV(TokenType.DIV, tokenSource, beginOffset, endOffset);
case NOTLIKE :
return new NOTLIKE(TokenType.NOTLIKE, tokenSource, beginOffset, endOffset);
case STAR :
return new STAR(TokenType.STAR, tokenSource, beginOffset, endOffset);
case EXCLAMATION :
return new EXCLAMATION(TokenType.EXCLAMATION, tokenSource, beginOffset, endOffset);
case GTEQ :
return new GTEQ(TokenType.GTEQ, tokenSource, beginOffset, endOffset);
case MATCHES :
return new MATCHES(TokenType.MATCHES, tokenSource, beginOffset, endOffset);
case EXPONENT :
return new EXPONENT(TokenType.EXPONENT, tokenSource, beginOffset, endOffset);
case STRING :
return new STRING(TokenType.STRING, tokenSource, beginOffset, endOffset);
case FALSE :
return new FALSE(TokenType.FALSE, tokenSource, beginOffset, endOffset);
case NEQ :
return new NEQ(TokenType.NEQ, tokenSource, beginOffset, endOffset);
case INVALID :
return new InvalidToken(tokenSource, beginOffset, endOffset);
default :
return new Token(type, tokenSource, beginOffset, endOffset);
}
}
public String getLocation() {
return getInputSource() + ":" + getBeginLine() + ":" + getBeginColumn();
}
public Node getParent() {
return parent;
}
public void setParent(Node parent) {
this.parent = parent;
}
public boolean isEmpty() {
return length() == 0;
}
public int length() {
return endOffset - beginOffset;
}
public CharSequence subSequence(int start, int end) {
return getTokenSource().subSequence(beginOffset + start, beginOffset + end);
}
public char charAt(int offset) {
return getTokenSource().charAt(beginOffset + offset);
}
/**
* @deprecated Use toString() instead
*/
@Deprecated
public String getImage() {
return getSource();
}
@Override
public String toString() {
return getSource();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy