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

com.github.leeonky.dal.token.AccessElementTokenCandidate Maven / Gradle / Ivy

There is a newer version: 0.8.1-alpha.6
Show newest version
package com.github.leeonky.dal.token;

import com.github.leeonky.dal.SyntaxException;

class AccessElementTokenCandidate extends TokenCandidate {

    AccessElementTokenCandidate(SourceCode sourceCode) {
        super(sourceCode);
    }

    @Override
    protected Token toToken() {
        if (!isFinished())
            throw new SyntaxException(getStartPosition() + content().length() + 1, "missed ']'");
        try {
            return Token.constIndexToken(Integer.valueOf(content()));
        } catch (NumberFormatException ignore) {
            return Token.propertyToken(content());
        }
    }

    @Override
    protected String discardedSuffix() {
        return "]";
    }

    @Override
    protected boolean isDiscardBeginChar() {
        return true;
    }

    @Override
    protected boolean isUnexpectedChar(char c) {
        return false;
    }
}

class AccessElementTokenCandidateFactory implements TokenCandidateFactory {

    static final AccessElementTokenCandidateFactory INSTANCE = new AccessElementTokenCandidateFactory();

    @Override
    public TokenCandidate createTokenCandidate(SourceCode sourceCode) {
        return new AccessElementTokenCandidate(sourceCode);
    }

    @Override
    public boolean isBegin(SourceCode sourceCode) {
        return sourceCode.getChar() == '[';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy