Search in sources :

Example 1 with Token

use of io.shardingjdbc.core.parsing.lexer.token.Token in project sharding-jdbc by shardingjdbc.

the class AbstractCreateParser method parseIndex.

private void parseIndex(final DDLStatement ddlStatement) {
    Token currentToken = lexerEngine.getCurrentToken();
    int beginPosition = currentToken.getEndPosition() - currentToken.getLiterals().length();
    String literals = currentToken.getLiterals();
    lexerEngine.skipUntil(DefaultKeyword.ON);
    lexerEngine.nextToken();
    String tableName = lexerEngine.getCurrentToken().getLiterals();
    ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, tableName));
}
Also used : IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken) Token(io.shardingjdbc.core.parsing.lexer.token.Token) IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken)

Example 2 with Token

use of io.shardingjdbc.core.parsing.lexer.token.Token in project sharding-jdbc by shardingjdbc.

the class Lexer method nextToken.

/**
 * Analyse next token.
 */
public final void nextToken() {
    skipIgnoredToken();
    if (isVariableBegin()) {
        currentToken = new Tokenizer(input, dictionary, offset).scanVariable();
    } else if (isNCharBegin()) {
        currentToken = new Tokenizer(input, dictionary, ++offset).scanChars();
    } else if (isIdentifierBegin()) {
        currentToken = new Tokenizer(input, dictionary, offset).scanIdentifier();
    } else if (isHexDecimalBegin()) {
        currentToken = new Tokenizer(input, dictionary, offset).scanHexDecimal();
    } else if (isNumberBegin()) {
        currentToken = new Tokenizer(input, dictionary, offset).scanNumber();
    } else if (isSymbolBegin()) {
        currentToken = new Tokenizer(input, dictionary, offset).scanSymbol();
    } else if (isCharsBegin()) {
        currentToken = new Tokenizer(input, dictionary, offset).scanChars();
    } else if (isEnd()) {
        currentToken = new Token(Assist.END, "", offset);
    } else {
        throw new SQLParsingException(this, Assist.ERROR);
    }
    offset = currentToken.getEndPosition();
}
Also used : SQLParsingException(io.shardingjdbc.core.parsing.parser.exception.SQLParsingException) Token(io.shardingjdbc.core.parsing.lexer.token.Token) Tokenizer(io.shardingjdbc.core.parsing.lexer.analyzer.Tokenizer)

Example 3 with Token

use of io.shardingjdbc.core.parsing.lexer.token.Token in project sharding-jdbc by shardingjdbc.

the class Tokenizer method scanSymbol.

/**
 * scan symbol.
 *
 * @return symbol token
 */
public Token scanSymbol() {
    int length = 0;
    while (CharType.isSymbol(charAt(offset + length))) {
        length++;
    }
    String literals = input.substring(offset, offset + length);
    Symbol symbol;
    while (null == (symbol = Symbol.literalsOf(literals))) {
        literals = input.substring(offset, offset + --length);
    }
    return new Token(symbol, literals, offset + length);
}
Also used : Symbol(io.shardingjdbc.core.parsing.lexer.token.Symbol) Token(io.shardingjdbc.core.parsing.lexer.token.Token)

Example 4 with Token

use of io.shardingjdbc.core.parsing.lexer.token.Token in project sharding-jdbc by shardingjdbc.

the class LexerAssert method assertNextToken.

public static void assertNextToken(final Lexer lexer, final TokenType expectedTokenType, final String expectedLiterals) {
    lexer.nextToken();
    Token actualToken = lexer.getCurrentToken();
    assertThat(actualToken.getType(), is(expectedTokenType));
    assertThat(actualToken.getLiterals(), is(expectedLiterals));
}
Also used : Token(io.shardingjdbc.core.parsing.lexer.token.Token)

Example 5 with Token

use of io.shardingjdbc.core.parsing.lexer.token.Token in project sharding-jdbc by shardingjdbc.

the class AbstractDropParser method parseIndex.

private void parseIndex(final DDLStatement ddlStatement) {
    Token currentToken = lexerEngine.getCurrentToken();
    int beginPosition = currentToken.getEndPosition() - currentToken.getLiterals().length();
    String literals = currentToken.getLiterals();
    lexerEngine.skipUntil(DefaultKeyword.ON);
    if (lexerEngine.skipIfEqual(DefaultKeyword.ON)) {
        tableReferencesClauseParser.parseSingleTableWithoutAlias(ddlStatement);
        ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, ddlStatement.getTables().getSingleTableName()));
    } else {
        ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, ""));
    }
}
Also used : IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken) Token(io.shardingjdbc.core.parsing.lexer.token.Token) IndexToken(io.shardingjdbc.core.parsing.parser.token.IndexToken)

Aggregations

Token (io.shardingjdbc.core.parsing.lexer.token.Token)5 IndexToken (io.shardingjdbc.core.parsing.parser.token.IndexToken)2 Tokenizer (io.shardingjdbc.core.parsing.lexer.analyzer.Tokenizer)1 Symbol (io.shardingjdbc.core.parsing.lexer.token.Symbol)1 SQLParsingException (io.shardingjdbc.core.parsing.parser.exception.SQLParsingException)1