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

The following examples show how to use com.intellij.lang.PsiBuilder#error() . 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: PreprocessorExpressionParsing.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
private static PsiBuilder.Marker parseUnary(final PsiBuilder builder)
{
	final IElementType tokenType = builder.getTokenType();

	if(PREFIX_OPS.contains(tokenType))
	{
		final PsiBuilder.Marker unary = builder.mark();
		builder.advanceLexer();

		final PsiBuilder.Marker operand = parseUnary(builder);
		if(operand == null)
		{
			builder.error("Expression expected");
		}

		unary.done(PREFIX_EXPRESSION);
		return unary;
	}
	else
	{
		return parsePrimary(builder);
	}
}
 
Example 2
Source File: SharedParsingHelpers.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
public static boolean expect(PsiBuilder builder, IElementType elementType, String message)
{
	if(builder.getTokenType() == elementType)
	{
		builder.advanceLexer();
		return true;
	}
	else
	{
		if(message != null)
		{
			builder.error(message);
		}
		return false;
	}
}
 
Example 3
Source File: SharedParsingHelpers.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
protected static boolean expect(PsiBuilder builder, TokenSet tokenSet, String message)
{
	if(tokenSet.contains(builder.getTokenType()))
	{
		builder.advanceLexer();
		return true;
	}
	else
	{
		if(message != null)
		{
			builder.error(message);
		}
		return false;
	}
}
 
Example 4
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 5
Source File: ParserUtil.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
public static boolean smartRemapAndAdvance(PsiBuilder builder, String expectedTokenText, IElementType expectedTokenType, IElementType newTokenType) {
    IElementType current = builder.getTokenType();
    if (current == newTokenType) {
        // already remapped, probably due to reverting an earlier parse result
        builder.advanceLexer();
    } else if (expectedTokenText.equals(builder.getTokenText()) && current == expectedTokenType) {
        builder.remapCurrentToken(newTokenType);
        builder.advanceLexer();
    } else {
        builder.error("unexpected token");
        return false;
    }

    return true;
}
 
Example 6
Source File: ShaderLabParser.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
public static boolean parseBracketReference(PsiBuilder builder)
{
	if(expectWithError(builder, ShaderLabTokens.LBRACKET, "'[' expected"))
	{
		if(!parseReference(builder))
		{
			builder.error("Expected reference");
		}
		expectWithError(builder, ShaderLabTokens.RBRACKET, "']' expected");
		return true;
	}
	return false;
}
 
Example 7
Source File: ShaderLabParser.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
public static boolean expectWithError(PsiBuilder builder, IElementType elementType, @Nonnull String message)
{
	if(PsiBuilderUtil.expect(builder, elementType))
	{
		return true;
	}
	else
	{
		builder.error(message);
		return false;
	}
}
 
Example 8
Source File: ShaderLabBlendRole.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private static void parseValue(PsiBuilder builder)
{
	if(builder.getTokenType() == ShaderLabTokens.LBRACKET)
	{
		ShaderLabParser.parseBracketReference(builder);
	}
	else if(builder.getTokenType() == ShaderLabTokens.IDENTIFIER)
	{
		ShaderLabParser.validateIdentifier(builder, ourFactors);
	}
	else
	{
		builder.error("Unexpected token");
	}
}
 
Example 9
Source File: PreprocessorExpressionParsing.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
private static PsiBuilder.Marker parsePrimaryExpressionStart(final PsiBuilder builder)
{
	IElementType tokenType = builder.getTokenType();


	if(tokenType == IDENTIFIER)
	{
		PsiBuilder.Marker refExpr = builder.mark();

		builder.advanceLexer();
		refExpr.done(REFERENCE_EXPRESSION);
		return refExpr;
	}

	if(tokenType == LPAR)
	{
		final PsiBuilder.Marker parenth = builder.mark();
		builder.advanceLexer();

		final PsiBuilder.Marker inner = parse(builder);
		if(inner == null)
		{
			builder.error("Expression expected");
		}

		if(!SharedParsingHelpers.expect(builder, RPAR, null))
		{
			if(inner != null)
			{
				builder.error("')' expected");
			}
		}

		parenth.done(PARENTHESES_EXPRESSION);
		return parenth;
	}
	return null;
}
 
Example 10
Source File: SharedParsingHelpers.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public static void reportIdentifier(PsiBuilder builder, int flags)
{
	PsiBuilder.Marker mark = builder.mark();
	builder.error("Expected identifier");
	mark.done(BitUtil.isSet(flags, STUB_SUPPORT) ? CSharpStubElements.IDENTIFIER : CSharpElements.IDENTIFIER);
	mark.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_LEFT_BINDER, null);
}
 
Example 11
Source File: CSharpFragmentFactory.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ASTNode parse(@Nonnull IElementType elementType, @Nonnull PsiBuilder builder, @Nonnull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();
	ExpressionParsing.parse(new CSharpBuilderWrapper(builder, languageVersion), ModifierSet.EMPTY);
	while(!builder.eof())
	{
		builder.error("Unexpected token");
		builder.advanceLexer();
	}
	mark.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 12
Source File: CSharpFragmentFactory.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ASTNode parse(@Nonnull IElementType elementType, @Nonnull PsiBuilder builder, @Nonnull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();
	SharedParsingHelpers.parseType(new CSharpBuilderWrapper(builder, languageVersion), SharedParsingHelpers.VAR_SUPPORT);
	while(!builder.eof())
	{
		builder.error("Unexpected token");
		builder.advanceLexer();
	}
	mark.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 13
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();
    }
}
 
Example 14
Source File: ParserUtil.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
public static void error(PsiBuilder builder, @PropertyKey(resourceBundle = BUNDLE) String message) {
    builder.error(BashStrings.message(message));
}
 
Example 15
Source File: PreprocessorExpressionParsing.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nullable
private static PsiBuilder.Marker parseBinary(final PsiBuilder builder, final ExprType type, final TokenSet ops)
{
	PsiBuilder.Marker result = parseExpression(builder, type);
	if(result == null)
	{
		return null;
	}
	int operandCount = 1;

	IElementType tokenType = builder.getTokenType();
	IElementType currentExprTokenType = tokenType;
	while(true)
	{
		if(tokenType == null || !ops.contains(tokenType))
		{
			break;
		}

		builder.advanceLexer();

		final PsiBuilder.Marker right = parseExpression(builder, type);
		operandCount++;
		tokenType = builder.getTokenType();
		if(tokenType == null || !ops.contains(tokenType) || tokenType != currentExprTokenType || right == null)
		{
			// save
			result = result.precede();
			if(right == null)
			{
				builder.error("Expression expected");
			}
			result.done(operandCount > 2 ? POLYADIC_EXPRESSION : BINARY_EXPRESSION);
			if(right == null)
			{
				break;
			}
			currentExprTokenType = tokenType;
			operandCount = 1;
		}
	}

	return result;
}