Java Code Examples for com.intellij.lang.PsiBuilder#advanceLexer()
The following examples show how to use
com.intellij.lang.PsiBuilder#advanceLexer() .
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: CSharpFileFactory.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nonnull private static IElementType createElementType(String id, BiConsumer<PsiBuilder, LanguageVersion> consumer) { return new IFileElementType(id, CSharpLanguage.INSTANCE) { @Override protected ASTNode doParseContents(@Nonnull ASTNode chameleon, @Nonnull PsiElement psi) { final Project project = psi.getProject(); final Language languageForParser = getLanguageForParser(psi); final LanguageVersion tempLanguageVersion = chameleon.getUserData(LanguageVersion.KEY); final LanguageVersion languageVersion = tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion; final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion, chameleon.getChars()); consumer.accept(builder, languageVersion); while(!builder.eof()) { builder.advanceLexer(); } return builder.getTreeBuilt(); } }; }
Example 2
Source File: SharedParsingHelpers.java From consulo-csharp with Apache License 2.0 | 6 votes |
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 3
Source File: GLSLParser.java From glsl4idea with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void parseLight(IElementType root, PsiBuilder builder) { if (crashing) { builder.setDebugMode(true); } final PsiBuilder.Marker rootMarker = builder.mark(); if (!builder.eof()) { //Empty file is not an error final GLSLParsing theRealParser = new GLSLParsing(builder); theRealParser.parseTranslationUnit(); while (!builder.eof()) // exhaust the file if unable to parse everything builder.advanceLexer(); } rootMarker.done(root); }
Example 4
Source File: SharedParsingHelpers.java From consulo-csharp with Apache License 2.0 | 6 votes |
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 5
Source File: MMPsiParser.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
private void parseTopics(@Nonnull final PsiBuilder builder) { while (!builder.eof()) { final PsiBuilder.Marker marker = builder.mark(); final IElementType token = builder.getTokenType(); if (token == null) { marker.drop(); } else { if (token == MMTokens.TOPIC_LEVEL) { final PsiBuilder.Marker levelMarker = builder.mark(); levelMarker.done(token); final int topicLevel = ModelUtils.calcCharsOnStart('#', builder.getTokenText()); if (topicLevel != 1) { marker.done(MMTokens.UNKNOWN); } else { builder.advanceLexer(); recursiveParseTopic(builder, topicLevel); marker.done(MMTokens.TOPIC); } } else { marker.done(MMTokens.UNKNOWN); } } builder.advanceLexer(); } }
Example 6
Source File: MMPsiParser.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
private void parseHeader(@Nonnull final PsiBuilder builder) { boolean doLoop = true; while (doLoop && !builder.eof()) { final PsiBuilder.Marker marker = builder.mark(); if (builder.getTokenType() == null) { marker.drop(); } else { final IElementType token = builder.getTokenType(); if (token == MMTokens.HEADER_DELIMITER) { marker.done(token); doLoop = false; } else if (token == MMTokens.HEADER_LINE || token == MMTokens.UNKNOWN || token == MMTokens.WHITE_SPACE || token == MMTokens.ATTRIBUTES) { marker.done(token); } else { throw Assertions.fail("Unexpected header token : " + token); } } builder.advanceLexer(); } }
Example 7
Source File: IndentationParser.java From consulo with Apache License 2.0 | 5 votes |
private void passEOLsAndIndents(@Nonnull final PsiBuilder builder) { IElementType tokenType = builder.getTokenType(); while (tokenType == myEolTokenType || tokenType == myIndentTokenType) { builder.advanceLexer(); tokenType = builder.getTokenType(); } }
Example 8
Source File: UnescapingPsiBuilder.java From BashSupport with Apache License 2.0 | 5 votes |
/** * @param exact if true then positions should be equal; * else delegate should be behind, not including exactly all foreign (skipped) or whitespace tokens */ private void synchronizePositions(boolean exact) { final PsiBuilder delegate = getDelegate(); if (myLexPosition >= myShrunkSequenceSize || delegate.eof()) { myLexPosition = myShrunkSequenceSize; while (!delegate.eof()) { delegate.advanceLexer(); } return; } if (delegate.getCurrentOffset() > myShrunkSequence.get(myLexPosition).realStart) { LOG.debug("delegate is ahead of my builder!"); return; } final int keepUpPosition = getKeepUpPosition(exact); while (!delegate.eof()) { final int delegatePosition = delegate.getCurrentOffset(); if (delegatePosition < keepUpPosition) { delegate.advanceLexer(); } else { break; } } }
Example 9
Source File: CSharpFragmentFactory.java From consulo-csharp with Apache License 2.0 | 5 votes |
@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 10
Source File: ParserUtil.java From BashSupport with Apache License 2.0 | 5 votes |
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 11
Source File: HaxeExpressionCodeFragmentImpl.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi) { final PsiBuilderFactory factory = PsiBuilderFactory.getInstance(); final PsiBuilder psiBuilder = factory.createBuilder(getProject(), chameleon); final PsiBuilder builder = adapt_builder_(HaxeTokenTypes.EXPRESSION, psiBuilder, new HaxeParser()); final PsiBuilder.Marker marker = enter_section_(builder, 0, _NONE_, "<code fragment>"); HaxeParser.expression(builder, 1); while (builder.getTokenType() != null) { builder.advanceLexer(); } marker.done(HaxeTokenTypes.EXPRESSION); return builder.getTreeBuilt(); }
Example 12
Source File: PreprocessorExpressionParsing.java From consulo-csharp with Apache License 2.0 | 5 votes |
@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 13
Source File: MakefileParserDefinition.java From CppTools with Apache License 2.0 | 5 votes |
@NotNull public ASTNode parse(IElementType iElementType, PsiBuilder psiBuilder) { final PsiBuilder.Marker marker = psiBuilder.mark(); PsiBuilder.Marker statement = psiBuilder.mark(); IElementType statementType = null; while(!psiBuilder.eof()) { final IElementType tokenType = psiBuilder.getTokenType(); if (tokenType == MakefileTokenTypes.SEMANTIC_WHITESPACE) { psiBuilder.advanceLexer(); statement.done(statementType != null ? statementType:MakefileTokenTypes.STATEMENT); statementType = null; statement = psiBuilder.mark(); continue; } else if (shouldProduceComposite(tokenType)) { PsiBuilder.Marker identifier = psiBuilder.mark(); psiBuilder.advanceLexer(); identifier.done(tokenType); continue; } else if (tokenType == MakefileTokenTypes.VAR_DEFINITION) { statementType = tokenType; } else if (tokenType == MakefileTokenTypes.IDENTIFIER_START) { readIdentifier(psiBuilder, MakefileTokenTypes.IDENTIFIER_END, MakefileTokenTypes.IDENTIFIER); } else if (tokenType == MakefileTokenTypes.TARGET_IDENTIFIER_START) { readIdentifier(psiBuilder, MakefileTokenTypes.TARGET_IDENTIFIER_END, MakefileTokenTypes.TARGET_IDENTIFIER); if (!psiBuilder.eof()) psiBuilder.advanceLexer(); statementType = MakefileTokenTypes.TARGET_DECLARATION; continue; } psiBuilder.advanceLexer(); } statement.done(MakefileTokenTypes.STATEMENT); marker.done(iElementType); return psiBuilder.getTreeBuilt(); }
Example 14
Source File: LatteParserUtil.java From intellij-latte with MIT License | 5 votes |
private static boolean isAutoEmptyPair(String macroName, PsiBuilder builder) { builder.advanceLexer(); if (isEmptyPair(builder)) { return true; } int pairMacrosLevel = 0; IElementType type = builder.getTokenType(); while (type != null) { if(type == T_HTML_TAG_NATTR_NAME && ("n:" + macroName).equals(builder.getTokenText())) { return false; } if (nextTokenIsFast(builder, T_MACRO_CLOSE_TAG_OPEN, T_MACRO_OPEN_TAG_OPEN)) { boolean closing = type == T_MACRO_CLOSE_TAG_OPEN; String macroName2 = getMacroName(builder); if (macroName2.equals(macroName)) { return closing; } else if (closing) { if (pairMacrosLevel == 0) { return true; } else { pairMacrosLevel--; } } else if (isClosingTagExpected(builder, macroName2)) { pairMacrosLevel++; } } builder.advanceLexer(); type = builder.getTokenType(); } return false; }
Example 15
Source File: LatteParserUtil.java From intellij-latte with MIT License | 5 votes |
private static boolean isEmptyPair(PsiBuilder builder) { IElementType type = builder.getTokenType(); while (type != null) { if (type == T_MACRO_TAG_CLOSE_EMPTY) { return true; } else if (type == T_MACRO_TAG_CLOSE) { return false; } builder.advanceLexer(); type = builder.getTokenType(); } return false; }
Example 16
Source File: ParserUtil.java From BashSupport with Apache License 2.0 | 4 votes |
public static void errorToken(PsiBuilder builder, @PropertyKey(resourceBundle = BUNDLE) String message) { PsiBuilder.Marker marker = builder.mark(); builder.advanceLexer(); marker.error(BashStrings.message(message)); }
Example 17
Source File: IndentationParser.java From consulo with Apache License 2.0 | 4 votes |
protected void advanceLexer(@Nonnull PsiBuilder builder) { builder.advanceLexer(); }
Example 18
Source File: DuneParser.java From reasonml-idea-plugin with MIT License | 4 votes |
@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 19
Source File: ShaderLabParser.java From consulo-unity3d with Apache License 2.0 | 4 votes |
public static void parseElementsInBraces(@Nonnull PsiBuilder builder, IElementType open, IElementType close, IElementType valid) { if(builder.getTokenType() == open) { builder.advanceLexer(); while(!builder.eof()) { IElementType tokenType = builder.getTokenType(); if(tokenType == close) { break; } if(valid != null) { if(tokenType == valid) { builder.advanceLexer(); } else { doneError(builder, "Unexpected token"); } } else { builder.advanceLexer(); } if(builder.getTokenType() == ShaderLabTokens.COMMA) { builder.advanceLexer(); } else if(builder.getTokenType() != close) { doneError(builder, "Unexpected token"); } } expectWithError(builder, close, "Unexpected token"); } }
Example 20
Source File: ShaderLabParser.java From consulo-unity3d with Apache License 2.0 | 4 votes |
public static void doneError(PsiBuilder builder, String message) { PsiBuilder.Marker mark = builder.mark(); builder.advanceLexer(); mark.error(message); }