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

The following examples show how to use com.intellij.lang.PsiBuilder#rawLookup() . 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: RmlParser.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
private void parseLt(@NotNull PsiBuilder builder, @NotNull ParserState state) {
    // Can be a symbol or a JSX tag
    IElementType nextTokenType = builder.rawLookup(1);
    if (nextTokenType == m_types.LIDENT || nextTokenType == m_types.UIDENT
            || nextTokenType == m_types.OPTION) { // Note that option is a ReasonML keyword but also a JSX keyword !
        // Surely a tag
        builder.remapCurrentToken(m_types.TAG_LT);
        state.add(mark(builder, jsxTag, m_types.C_TAG).complete())
                .add(markScope(builder, jsxStartTag, jsxStartTag, m_types.C_TAG_START, m_types.TAG_LT).complete());

        state.advance();

        builder.remapCurrentToken(m_types.TAG_NAME);
        state.wrapWith(nextTokenType == m_types.UIDENT ? m_types.C_UPPER_SYMBOL : m_types.C_LOWER_SYMBOL);
    }
}
 
Example 2
Source File: RmlParser.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
private void parseLtSlash(@NotNull PsiBuilder builder, @NotNull ParserState state) {
    IElementType nextTokenType = builder.rawLookup(1);
    if (nextTokenType == m_types.LIDENT || nextTokenType == m_types.UIDENT) {
        // A closing tag
        if (state.isCurrentContext(jsxTagBody)) {
            state.popEnd();
        }

        builder.remapCurrentToken(m_types.TAG_LT);
        state.add(mark(builder, jsxTagClose, m_types.C_TAG_CLOSE).complete());

        state.advance();

        builder.remapCurrentToken(m_types.TAG_NAME);
        state.wrapWith(nextTokenType == m_types.UIDENT ? m_types.C_UPPER_SYMBOL : m_types.C_LOWER_SYMBOL);
    }
}
 
Example 3
Source File: RmlParser.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
private void parseLBracket(@NotNull PsiBuilder builder, @NotNull ParserState state) {
    IElementType nextTokenType = builder.rawLookup(1);
    if (nextTokenType == m_types.ARROBASE) {
        if (state.isCurrentResolution(recordField)) {
            state.popEnd();
            state.add(markScope(builder, recordFieldAnnotation, annotation, m_types.C_ANNOTATION_EXPR, m_types.LBRACKET));
        } else {
            state.add(markScope(builder, annotation, m_types.C_ANNOTATION_EXPR, m_types.LBRACKET));
        }
    } else if (nextTokenType == m_types.PERCENT) {
        state.add(markScope(builder, macro, m_types.C_MACRO_EXPR, m_types.LBRACKET));
    } else {
        if (state.previousElementType2 == m_types.UIDENT && state.previousElementType1 == m_types.DOT) {
            // Local open
            // M.|>[<| ... ]
            state.add(markScope(builder, localOpen, m_types.C_LOCAL_OPEN, m_types.LBRACKET).complete());
        } else {
            state.add(markScope(builder, bracket, m_types.C_SCOPED_EXPR, m_types.LBRACKET));
        }
    }
}
 
Example 4
Source File: PathParser.java    From elm-plugin with MIT License 6 votes vote down vote up
private boolean listOfMembers(PsiBuilder builder, int level) {
    if (!recursion_guard_(builder, level, this.getGuardText(1))) return false;
    int c = current_position_(builder);
    boolean isContinued;
    while (true) {
        if (builder.rawLookup(0) != DOT) {
            break;
        }
        if (builder.rawLookup(1) != this.memberType
                && !trySwitchingMemberType(builder)) {
            break;
        }
        isContinued = builder.rawLookup(2) == DOT;
        if (!dotMember(builder, level + 1)) break;
        if (!empty_element_parsed_guard_(builder, this.getGuardText(1), c)) break;
        c = current_position_(builder);
        if (!isContinued) break;
    }
    return true;
}
 
Example 5
Source File: ParserUtil.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
public static boolean containsTokenInLookahead(PsiBuilder builder, IElementType token, int maxLookahead, boolean allowWhitespace) {
    int i = 0;

    while (i < maxLookahead) {
        IElementType current = allowWhitespace ? builder.lookAhead(i) : builder.rawLookup(i);
        if (current == null) {
            return false;
        }

        if (current == token) {
            return true;
        }

        i++;
    }

    return false;
}
 
Example 6
Source File: HaxeGeneratedParserUtilBase.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
/**
 * Make a semi-colon optional in the case that it's preceded by a block statement.
 *
 */
public static boolean semicolonUnlessPrecededByStatement(PsiBuilder builder_, int level) {
  if (consumeTokenFast(builder_, OSEMI)) {
    return true;
  }
  int i = -1;
  IElementType previousType = builder_.rawLookup(i);
  while (null != previousType && isWhitespaceOrComment(builder_, previousType)) {
    previousType = builder_.rawLookup(--i);
  }
  if (previousType == HaxeTokenTypes.PRCURLY || previousType == HaxeTokenTypes.OSEMI) {
    return true;
  }
  builder_.error(HaxeBundle.message("parsing.error.missing.semi.colon"));
  return false;
}
 
Example 7
Source File: RmlParser.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
private void parsePercent(@NotNull PsiBuilder builder, @NotNull ParserState state) {
    if (state.isCurrentResolution(macro)) {
        state.complete();
        state.add(mark(builder, macro, macroName, m_types.C_MACRO_NAME));
    } else if (state.isCurrentResolution(letNamed)) {
        // let name|>%<|private = ...
        state.add(mark(builder, state.currentContext(), letNamedAttribute, m_types.C_LET_ATTR));
    } else {
        IElementType nextTokenType = builder.rawLookup(1);
        if (nextTokenType == m_types.RAW) {
            state.add(mark(builder, raw, m_types.C_RAW));
        }
    }
}
 
Example 8
Source File: OclParser.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
private void parseLBracket(@NotNull PsiBuilder builder, @NotNull ParserState state) {
    if (state.isCurrentResolution(clazz)) {
        state.add(markScope(builder, clazzDeclaration, bracket, m_types.C_CLASS_PARAMS, m_types.LBRACKET));
    } else {
        IElementType nextTokenType = builder.rawLookup(1);
        if (nextTokenType == m_types.ARROBASE) {
            // This is an annotation
            state.popEndUntilStartScope();
            state.add(markScope(builder, annotation, m_types.C_ANNOTATION_EXPR, m_types.LBRACKET));
        } else {
            state.add(markScope(builder, bracket, m_types.C_SCOPED_EXPR, m_types.LBRACKET));
        }
    }
}
 
Example 9
Source File: EffectParser.java    From elm-plugin with MIT License 5 votes vote down vote up
@Override
public boolean parse(PsiBuilder builder, int level) {
    if (!recursion_guard_(builder, level, "EffectParser")) return false;
    if (builder.rawLookup(0) != LOWER_CASE_IDENTIFIER || !"effect".equals(builder.getTokenText()))
        return false;
    boolean result;
    PsiBuilder.Marker marker = enter_section_(builder);
    result = consumeTokens(builder, 0, LOWER_CASE_IDENTIFIER);
    exit_section_(builder, marker, EFFECT, result);
    return result;
}
 
Example 10
Source File: PathParser.java    From elm-plugin with MIT License 5 votes vote down vote up
@Override
public boolean parse(PsiBuilder builder, int level) {
    if (!recursion_guard_(builder, level, this.getGuardText())) return false;
    if (!nextTokenIs(builder, this.memberType)) return false;
    boolean result;
    boolean isContinued = builder.rawLookup(1) == DOT;
    PsiBuilder.Marker marker = enter_section_(builder);
    result = this.memberParser.parse(builder, level + 1); //consumeToken(builder, this.memberType);
    result = result && (!isContinued || listOfMembers(builder, level + 1));
    exit_section_(builder, marker, this.sectionType, result);
    return result;
}
 
Example 11
Source File: PathParser.java    From elm-plugin with MIT License 5 votes vote down vote up
private boolean trySwitchingMemberType(PsiBuilder builder) {
    if (this.alternativeMemberParser != null
            && builder.rawLookup(1) == this.alternativeMemberType) {
        this.memberType = this.alternativeMemberType;
        this.alternativeMemberType = null;
        this.memberParser = this.alternativeMemberParser;
        this.alternativeMemberParser = null;
        return true;
    }
    return false;
}
 
Example 12
Source File: FieldAccessParser.java    From elm-plugin with MIT License 5 votes vote down vote up
@Override
public boolean parse(PsiBuilder builder, int level) {
    if (!recursion_guard_(builder, level, "field_access")) return false;
    if (builder.rawLookup(0) != DOT
            || builder.rawLookup(1) != LOWER_CASE_IDENTIFIER
            || builder.rawLookup(2) == DOT)
        return false;
    boolean result;
    PsiBuilder.Marker marker = enter_section_(builder);
    result = consumeTokens(builder, 0, DOT, LOWER_CASE_IDENTIFIER);
    exit_section_(builder, marker, FIELD_ACCESS, result);
    return result;
}
 
Example 13
Source File: ParserUtil.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
public static boolean hasNextTokens(PsiBuilder builder, boolean enableWhitespace, IElementType... tokens) {
    for (int i = 0, tokensLength = tokens.length; i < tokensLength; i++) {
        IElementType lookAheadToken = enableWhitespace ? builder.rawLookup(i) : builder.lookAhead(i);
        if (lookAheadToken != tokens[i]) {
            return false;
        }
    }

    return true;
}
 
Example 14
Source File: HaskellParserUtilBase.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Pair<Integer, IElementType> previousElem(@NotNull PsiBuilder builder) {
    int i = -1;
    IElementType t = builder.rawLookup(i);
    while (t != null &&
            (HaskellParserDefinition.COMMENTS.contains(t) ||
                HaskellParserDefinition.WHITE_SPACES.contains(t))) {
        t = builder.rawLookup(--i);
    }
    return t == null ? null : Pair.create(i - 1, t);
}
 
Example 15
Source File: OclParser.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
private void parseLParen(@NotNull PsiBuilder builder, @NotNull ParserState state) {
    if (state.previousElementType2 == m_types.UIDENT && state.previousElementType1 == m_types.DOT) {
        // Detecting a local open
        //   M1.M2. |>(<| ... )
        state.add(markScope(builder, localOpenScope, m_types.C_LOCAL_OPEN, m_types.LPAREN).complete());
    } else if (state.isCurrentResolution(external)) {
        // Overloading an operator
        //   external |>(<| ... ) = ...
        state.updateCurrentResolution(externalNamed).complete();
        state.add(markScope(builder, localOpenScope, m_types.C_SCOPED_EXPR, m_types.LPAREN));
    } else if (state.isCurrentResolution(let)) {
        // Overloading operator OR deconstructing a term
        //   let |>(<| + ) =
        //   let |>(<| a, b ) =
        state.add(markScope(builder, let, genericExpression, m_types.C_SCOPED_EXPR, m_types.LPAREN));
    } else if (state.isCurrentResolution(val)) {
        // Overloading an operator
        //   val |>(<| .. ) = ..
        state.updateCurrentResolution(valNamed).complete();
        state.add(markScope(builder, valNamedSymbol, m_types.C_SCOPED_EXPR, m_types.LPAREN));
    } else if (state.isCurrentResolution(clazzNamed)) {
        state.add(markScope(builder, state.currentContext(), clazzConstructor, m_types.C_CLASS_CONSTR, m_types.LPAREN));
    } else if (state.isCurrentResolution(functionParameters)) {
        // Start of the first parameter
        //     let f |>(<| .. ) = ..
        state.add(mark(builder, functionParameters, functionParameter, m_types.C_FUN_PARAM)).
                add(markScope(builder, state.currentContext(), functionParameter, m_types.C_SCOPED_EXPR, m_types.LPAREN));
    } else if (state.isCurrentResolution(functionParameter) && !state.isInScopeExpression() && state.previousElementType1 != m_types.QUESTION_MARK) {
        // Start of a new parameter
        //    let f xxx |>(<| ..tuple ) = ..
        state.complete().popEnd().
                add(mark(builder, state.currentContext(), functionParameter, m_types.C_FUN_PARAM)).
                add(markScope(builder, state.currentContext(), functionParameter, m_types.C_SCOPED_EXPR, m_types.LPAREN));
    } else if (state.isCurrentResolution(functionParameters)) {
        state.add(mark(builder, functionParameters, functionParameter, m_types.C_FUN_PARAM));

        IElementType nextTokenType = builder.rawLookup(1);
        if (nextTokenType == m_types.RPAREN) {
            // unit parameter
            state.add(mark(builder, state.currentContext(), unit, m_types.C_UNIT).
                    complete()).
                    advance().
                    advance().
                    popEnd();
        }
    } else if (state.isCurrentResolution(moduleNamed)) {
        // This is a functor
        //   module Make |>(<| ... )
        state.updateCurrentContext(functorDeclaration).
                updateCurrentResolution(functorNamed).
                updateCurrentCompositeElementType(m_types.C_FUNCTOR).
                add(markScope(builder, functorDeclarationParams, functorParams, m_types.C_FUNCTOR_PARAMS, m_types.LPAREN)).
                advance().
                add(mark(builder, state.currentContext(), functorParam, m_types.C_FUNCTOR_PARAM).complete());
    } else if (state.isCurrentResolution(maybeFunctorCall)) {
        // Yes, it is a functor call
        //   module M = X |>(<| ... )
        state.updateCurrentResolution(functorCall).complete();
        state.add(markScope(builder, functorDeclarationParams, functorParams, m_types.C_FUNCTOR_PARAMS, m_types.LPAREN)).
                advance().
                add(mark(builder, state.currentContext(), functorParam, m_types.C_FUNCTOR_PARAM).complete());
    } else {
        state.add(markScope(builder, scope, paren, m_types.C_SCOPED_EXPR, m_types.LPAREN));
    }
}