Java Code Examples for com.intellij.lang.PsiBuilder#rawTokenIndex()

The following examples show how to use com.intellij.lang.PsiBuilder#rawTokenIndex() . 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: DuneParser.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@Override
protected void parseFile(@NotNull PsiBuilder builder, @NotNull ParserState state) {
    IElementType tokenType = null;

    //long parseStart = System.currentTimeMillis();

    int c = current_position_(builder);
    while (true) {
        //long parseTime = System.currentTimeMillis();
        //if (5 < parseTime - parseStart) {
        // Protection: abort the parsing if too much time spent
        //break;
        //}

        state.previousElementType1 = tokenType;
        tokenType = builder.getTokenType();
        if (tokenType == null) {
            break;
        }

        // ( .. )
        if (tokenType == m_types.LPAREN) {
            parseLParen(builder, state);
        } else if (tokenType == m_types.RPAREN) {
            if (state.isCurrentResolution(stanzaNamedFields)) {
                state.popEnd();
            }

            if (state.isInScopeExpression()) {
                state.complete();
                state.advance();
                state.popEnd();
            } else {
                builder.error("Unbalanced parenthesis");
            }
        }

        // %{ .. }
        else if (tokenType == m_types.VAR_START) {
            parseVarStart(builder, state);
        } else if (tokenType == m_types.VAR_END) {
            parseVarEnd(builder, state);
        } else if (tokenType == m_types.ATOM) {
            parseAtom(builder, state);
        }

        if (state.dontMove) {
            state.dontMove = false;
        } else {
            builder.advanceLexer();
        }

        if (!empty_element_parsed_guard_(builder, "duneFile", c)) {
            break;
        }

        c = builder.rawTokenIndex();
    }
}