Java Code Examples for org.antlr.v4.runtime.CharStream#consume()

The following examples show how to use org.antlr.v4.runtime.CharStream#consume() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Session.java    From antsdb with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void skipComments(CharStream cs) {
    int idx = cs.index();
    if (cs.LA(1) == '/') {
        cs.consume();
        if (cs.LA(1) == '*') {
            cs.consume();
            for (;;) {
                int ch = cs.LA(1);
                cs.consume();
                if (ch == IntStream.EOF) break;
                if (ch == '/') {
                    break;
                }
            }
            return;
        }
    }
    cs.seek(idx);
}
 
Example 2
Source File: ContextDependentFEELLexer.java    From jdmn with Apache License 2.0 5 votes vote down vote up
private int nextChar(CharStream inputTape) {
    int ch = currentChar(inputTape);
    if (ch != IntStream.EOF) {
        inputTape.consume();
        ch = currentChar(inputTape);
    }
    return ch;
}
 
Example 3
Source File: Session.java    From antsdb with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Script parse0(CharBuffer cbuf) {
    if (this.isClosed.get()) {
        throw new OrcaException("session is closed");
    }

    CharStream cs = new CharBufferStream(cbuf);
    startTrx();
    
    // check the global statement cache
    Script script = this.getOrca().getCachedStatement(cs.toString());

    // skip leading comments
    skipComments(cs);
    skipSpaces(cs);
    
    // parse it for real if it is not cached
    if (script == null) {
        try {
            if (cs.LA(1) == '.') {
                cs.consume();
                script = this.fishParser.parse(this, cs);
            }
            else {
                script = this.fac.parse(this, cs);
            }
        }
        catch (CompileDdlException x) {
            script = new Script(null, x.nParameters, 100, cs.toString());
        }
        if (_log.isTraceEnabled()) {
            _log.trace("{}-{}: {}", getId(), script.hashCode(), cs.toString());
        }
        if (script.worthCache()) {
            this.getOrca().cacheStatement(script);
        }
    }
    return script;
}
 
Example 4
Source File: Session.java    From antsdb with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void skipSpaces(CharStream cs) {
    for (;;) {
        if (Character.isWhitespace(cs.LA(1))) {
            cs.consume();
        }
        else {
            break;
        }
    }
}