private static void advanceGtToken(final PsiBuilder builder, final IElementType type) { final PsiBuilder.Marker gtToken = builder.mark(); if (type == JavaTokenType.GTGTGTEQ) { PsiBuilderUtil.advance(builder, 4); } else if (type == JavaTokenType.GTGTGT || type == JavaTokenType.GTGTEQ) { PsiBuilderUtil.advance(builder, 3); } else if (type == JavaTokenType.GTGT || type == JavaTokenType.GE) { PsiBuilderUtil.advance(builder, 2); } else { gtToken.drop(); builder.advanceLexer(); return; } gtToken.collapse(type); }
private void parseSimpleTag(PsiBuilder builder, IElementType endElementType, IElementType to) { PsiBuilder.Marker mark = builder.mark(); builder.advanceLexer(); while(!builder.eof() && builder.getTokenType() != endElementType) { builder.advanceLexer(); } if(!PsiBuilderUtil.expect(builder, endElementType)) { builder.error("%> expected"); } mark.done(to); }
public static boolean expectWithError(PsiBuilder builder, IElementType elementType, @NotNull String message) { if(PsiBuilderUtil.expect(builder, elementType)) { return true; } else { builder.error(message); return false; } }
private static boolean expect(PsiBuilder builder, TokenSet tokenSet, String text) { if(!PsiBuilderUtil.expect(builder, tokenSet)) { if(text != null) { builder.error(text); } return false; } else { return true; } }
private static boolean expect(PsiBuilder builder, IElementType tokenSet, String text) { if(!PsiBuilderUtil.expect(builder, tokenSet)) { if(text != null) { builder.error(text); } return false; } else { return true; } }
public static boolean expectOrError(PsiBuilder builder, TokenSet expected, @PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String key) { if(!PsiBuilderUtil.expect(builder, expected)) { error(builder, JavaErrorMessages.message(key)); return false; } return true; }
public static boolean expectOrError(PsiBuilder builder, IElementType expected, @PropertyKey(resourceBundle = JavaErrorMessages.BUNDLE) String key) { if(!PsiBuilderUtil.expect(builder, expected)) { error(builder, JavaErrorMessages.message(key)); return false; } return true; }
@Override public PsiBuilder.Marker parseAndDone(ShaderLabParserBuilder builder, @NotNull PsiBuilder.Marker mark) { parseBefore(builder); if(PsiBuilderUtil.expect(builder, ShaderLabTokens.LBRACE)) { //TODO [VISTALL] hack until full syntax parse int count = 0; loop: while(!builder.eof()) { for(ShaderLabRole role : myRoles) { if(role.tryParse(builder)) { continue loop; } } IElementType tokenType = builder.getTokenType(); if(tokenType == ShaderLabTokens.LBRACE) { count++; } if(tokenType == ShaderLabTokens.RBRACE) { if(count == 0) { break; } count--; } if(tokenType == ShaderLabTokens.CGINCLUDE_KEYWORD || tokenType == ShaderLabTokens.CGPROGRAM_KEYWORD) { PsiBuilder.Marker marker = builder.mark(); builder.advanceLexer(); if(builder.getTokenType() == ShaderLabTokens.SHADERSCRIPT) { builder.advanceLexer(); } ShaderLabParser.expectWithError(builder, ShaderLabTokens.ENDCG_KEYWORD, "Expected 'ENDCG'"); marker.done(ShaderLabElements.CG_SHADER); } else { builder.advanceLexer(); } } if(!PsiBuilderUtil.expect(builder, ShaderLabTokens.RBRACE)) { builder.error("'}' expected"); } } else { builder.error("'{' expected"); } mark.done(myDoneElement); return mark; }
private void parseDirective(PsiBuilder builder) { PsiBuilder.Marker mark = builder.mark(); builder.advanceLexer(); if(!PsiBuilderUtil.expect(builder, XmlTokenType.XML_TAG_NAME)) { builder.error("Identifier expected"); } else { while(true) { if(builder.getTokenType() == XmlTokenType.XML_NAME) { PsiBuilder.Marker attMark = builder.mark(); builder.advanceLexer(); if(PsiBuilderUtil.expect(builder, XmlTokenType.XML_EQ)) { PsiBuilder.Marker attributeValueMarker = builder.mark(); if(PsiBuilderUtil.expect(builder, XmlTokenType.XML_ATTRIBUTE_VALUE_START_DELIMITER)) { PsiBuilderUtil.expect(builder, XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN); if(!PsiBuilderUtil.expect(builder, XmlTokenType.XML_ATTRIBUTE_VALUE_END_DELIMITER)) { builder.error("Excted attribute value stopper"); } attributeValueMarker.done(XmlElementType.XML_ATTRIBUTE_VALUE); } else { attributeValueMarker.error("Expected attribute start"); } } else { builder.error("'=' expected"); } attMark.done(XmlElementType.XML_ATTRIBUTE); } else if(builder.getTokenType() == XmlTokenType.XML_EMPTY_ELEMENT_END) { break; } else { builder.error("Identifier expected"); break; } } } if(!PsiBuilderUtil.expect(builder, XmlTokenType.XML_EMPTY_ELEMENT_END)) { builder.error("'%>' expected"); } mark.done(JspElements.DIRECTIVE); }
@NotNull @Override public ASTNode parse(@NotNull IElementType elementType, @NotNull PsiBuilder builder, @NotNull LanguageVersion languageVersion) { PsiBuilder.Marker mark = builder.mark(); while(!builder.eof()) { if(builder.getTokenType() == CfsTokens.START) { PsiBuilder.Marker itemMark = builder.mark(); builder.advanceLexer(); if(!PsiBuilderUtil.expect(builder, myArgumentElementType)) { builder.error("Argument expected"); } if(builder.getTokenType() == CfsTokens.COMMA) { builder.advanceLexer(); if(!PsiBuilderUtil.expect(builder, CfsTokens.ALIGN)) { builder.error("Align expected"); } } if(builder.getTokenType() == CfsTokens.COLON) { builder.advanceLexer(); if(!PsiBuilderUtil.expect(builder, CfsTokens.FORMAT)) { builder.error("Format expected"); } } if(!PsiBuilderUtil.expect(builder, CfsTokens.END)) { builder.error("} expected"); } itemMark.done(CfsElements.ITEM); } else { builder.advanceLexer(); } } mark.done(elementType); return builder.getTreeBuilt(); }