com.intellij.lang.PsiParser Java Examples
The following examples show how to use
com.intellij.lang.PsiParser.
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: CSharpFileStubElementType.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction @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 CSharpLanguageVersionWrapper languageVersion = (CSharpLanguageVersionWrapper) (tempLanguageVersion == null ? psi.getLanguageVersion() : tempLanguageVersion); Set<String> defVariables = getStableDefines((PsiFile) psi); final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, languageVersion, chameleon.getChars()); builder.putUserData(PREPROCESSOR_VARIABLES, defVariables); final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(languageForParser).createParser(languageVersion); return parser.parse(this, builder, languageVersion).getFirstChildNode(); }
Example #2
Source File: BuildParserTest.java From intellij with Apache License 2.0 | 6 votes |
private ASTNode createAST(String text) { ParserDefinition definition = new BuildParserDefinition(); PsiParser parser = definition.createParser(getProject()); Lexer lexer = definition.createLexer(getProject()); PsiBuilderImpl psiBuilder = new PsiBuilderImpl( getProject(), null, definition, lexer, new CharTableImpl(), text, null, null); PsiBuilderAdapter adapter = new PsiBuilderAdapter(psiBuilder) { @Override public void error(String messageText) { super.error(messageText); errors.add(messageText); } }; return parser.parse(definition.getFileNodeType(), adapter); }
Example #3
Source File: CSharpPreprocessorElements.java From consulo-csharp with Apache License 2.0 | 5 votes |
@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, new _CSharpMacroLexer(), languageForParser, languageVersion, chameleon.getChars()); final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(languageForParser).createParser(languageVersion); return parser.parse(this, builder, languageVersion).getFirstChildNode(); }
Example #4
Source File: CSharpDocElements.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Override @RequiredReadAction protected ASTNode doParseContents(@Nonnull final ASTNode chameleon, @Nonnull final PsiElement psi) { final Project project = psi.getProject(); CSharpDocLanguage docLanguage = CSharpDocLanguage.INSTANCE; final LanguageVersion languageVersion = LanguageVersionUtil.findDefaultVersion(docLanguage); DeprecatedCSharpDocLexer docLexer = new DeprecatedCSharpDocLexer(); final PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, docLexer, docLanguage, languageVersion, chameleon.getChars()); final PsiParser parser = LanguageParserDefinitions.INSTANCE.forLanguage(docLanguage).createParser(languageVersion); return parser.parse(this, builder, languageVersion).getFirstChildNode(); }
Example #5
Source File: HaskellParserDefinition.java From intellij-haskforce with Apache License 2.0 | 5 votes |
@NotNull @Override public PsiParser createParser(final Project project) { switch (mode) { case NOOP: return new SimplePsiParser(); case UNWRAPPED: return new HaskellParser(); default: return new HaskellParserWrapper(); } }
Example #6
Source File: LanguageVersionableParserDefinition.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public PsiParser createParser(@Nonnull LanguageVersion languageVersion) { if(languageVersion instanceof LanguageVersionWithParsing) { return ((LanguageVersionWithParsing)languageVersion).createParser(); } throw new IllegalArgumentException("'createParser' need override for language version '" + languageVersion + "'"); }
Example #7
Source File: HaskellParserUtilBase.java From intellij-haskforce with Apache License 2.0 | 5 votes |
/** * Called when the parser gets confused from layout rules. * * Increases the debt of rbraces in the token remapper in * HaskellParserWrapper. When the remapper is in debt it will swallow * (=remap them to TokenType.WHITE_SPACE) synthetic rbraces until no debt * remains. */ public static boolean stateHackMess(@NotNull PsiBuilder builder, int level) { if (!(builder instanceof Builder)) return false; PsiParser wrapper = ((Builder) builder).parser; if (!(wrapper instanceof HaskellParserWrapper)) return false; // IElementType tok = builder.getTokenType(); int offs = builder.getCurrentOffset(); int line = StringUtil.offsetToLineNumber(builder.getOriginalText(), offs); int lineStart = StringUtil.lineColToOffset(builder.getOriginalText(), line, 1); Pair<Integer, Integer> p = ((HaskellParserWrapper) wrapper).debtPoints.get(offs); if (p != null && p.getSecond() == 0 && !((HaskellParserWrapper) wrapper).regressed) { ((HaskellParserWrapper) wrapper).maxRbraceDebt = ((HaskellParserWrapper) wrapper).debtPoints.get(offs).getFirst(); ((HaskellParserWrapper) wrapper).rbraceDebt = ((HaskellParserWrapper) wrapper).rbraceDebt - ((HaskellParserWrapper) wrapper).maxRbraceDebt; ((HaskellParserWrapper) wrapper).debtPoints.put(offs, Pair.create(((HaskellParserWrapper) wrapper).maxRbraceDebt, ((HaskellParserWrapper) wrapper).maxRbraceDebt)); } else if (((HaskellParserWrapper) wrapper).maxRbraceDebt == -1) { int numOpen = findBraces(((HaskellParserWrapper) wrapper).lexer.openBraces, offs, line, lineStart); ((HaskellParserWrapper) wrapper).maxRbraceDebt = numOpen; } // System.out.println("Confused at: " + offs + " line " + line + " on token " + tok // + " regressed: " + ((HaskellParserWrapper) wrapper).regressed + " max: " // + ((HaskellParserWrapper) wrapper).maxRbraceDebt); boolean ret = ((HaskellParserWrapper) wrapper).increaseRbraceDebt(builder.getCurrentOffset()); if (((HaskellParserWrapper) wrapper).maxRbraceDebt == 0) ((HaskellParserWrapper) wrapper).maxRbraceDebt = -1; return ret; }
Example #8
Source File: HaskellParserUtilBase.java From intellij-haskforce with Apache License 2.0 | 5 votes |
public static boolean indented(@NotNull PsiBuilder builder, int level, Parser geq) { if (!(builder instanceof Builder)) return false; PsiParser wrapper = ((Builder) builder).parser; if (!(wrapper instanceof HaskellParserWrapper)) return false; if (builder.eof()) return false; // IElementType currtok = builder.getTokenType(); Pair<Integer, IElementType> prevtok = previousElem(builder); if (prevtok == null) return true; int offs = builder.getCurrentOffset(); int line = StringUtil.offsetToLineNumber(builder.getOriginalText(), offs); int prevline = StringUtil.offsetToLineNumber(builder.getOriginalText(), offs + prevtok.getFirst()); if (prevline == line) return true; int thisLineStart = StringUtil.lineColToOffset(builder.getOriginalText(), line, 0); int prevLineStart = StringUtil.lineColToOffset(builder.getOriginalText(), prevline, 0); // CharSequence lineStuff = builder.getOriginalText().subSequence(thisLineStart, offs); CharSequence prevLineStuff = builder.getOriginalText().subSequence(prevLineStart, thisLineStart - 1); int indentation = indentationLevel(prevLineStuff); int myindentation = offs - thisLineStart; // String tokName = builder.getTokenText(); boolean geqVal = geq.parse(builder, level); if (geqVal && myindentation >= indentation || !geqVal && myindentation > indentation) return true; return false; }
Example #9
Source File: ProjectViewParserDefinition.java From intellij with Apache License 2.0 | 5 votes |
@Override public PsiParser createParser(Project project) { return (root, builder) -> { PsiBuilder.Marker rootMarker = builder.mark(); new ProjectViewPsiParser(builder).parseFile(); rootMarker.done(root); return builder.getTreeBuilt(); }; }
Example #10
Source File: BuckParserDefinition.java From buck with Apache License 2.0 | 4 votes |
@Override public PsiParser createParser(final Project project) { return new BuckParser(); }
Example #11
Source File: LatteParserDefinition.java From intellij-latte with MIT License | 4 votes |
@Override public PsiParser createParser(Project project) { return new LatteParser(); }
Example #12
Source File: MakefileParserDefinition.java From CppTools with Apache License 2.0 | 4 votes |
public PsiParser createParser(Project project) { return new MakefileParser(); }
Example #13
Source File: CppParserDefinition.java From CppTools with Apache License 2.0 | 4 votes |
@NotNull public PsiParser createParser(Project project) { return new CppParser(); }
Example #14
Source File: DustParserDefinition.java From Intellij-Dust with MIT License | 4 votes |
@NotNull public PsiParser createParser(final Project project) { return new DustParser(); }
Example #15
Source File: BaseSandLanguageVersion.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public PsiParser createParser() { return new SandParser(myValue.getValue()); }
Example #16
Source File: LanguageVersionWithParsing.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull PsiParser createParser();
Example #17
Source File: ThriftParserDefinition.java From intellij-thrift with Apache License 2.0 | 4 votes |
public PsiParser createParser(Project project) { return new ThriftParser(); }
Example #18
Source File: BcfgParserDefinition.java From buck with Apache License 2.0 | 4 votes |
@NotNull @Override public PsiParser createParser(final Project project) { return new BcfgParser(); }
Example #19
Source File: CSharpDocParserDefinition.java From consulo-csharp with Apache License 2.0 | 4 votes |
@Nonnull @Override public PsiParser createParser(@Nonnull LanguageVersion languageVersion) { return new CSharpDocParser(); }
Example #20
Source File: HaxeParserDefinition.java From intellij-haxe with Apache License 2.0 | 4 votes |
public PsiParser createParser(Project project) { return new HaxeParserWrapper(); }
Example #21
Source File: GLSLParserDefinition.java From glsl4idea with GNU Lesser General Public License v3.0 | 4 votes |
public PsiParser createParser(Project project) { return new GLSLParser(); }
Example #22
Source File: RTParserDefinition.java From react-templates-plugin with MIT License | 4 votes |
@NotNull @Override public PsiParser createParser(Project project) { return new RTParser(); }
Example #23
Source File: ConceptParserDefinition.java From Intellij-Plugin with Apache License 2.0 | 4 votes |
@NotNull public PsiParser createParser(final Project project) { return new ConceptParser(); }
Example #24
Source File: SpecParserDefinition.java From Intellij-Plugin with Apache License 2.0 | 4 votes |
@NotNull public PsiParser createParser(final Project project) { return new SpecParser(); }
Example #25
Source File: CabalParserDefinition.java From intellij-haskforce with Apache License 2.0 | 4 votes |
@Override public PsiParser createParser(Project project) { return new CabalParser(); }
Example #26
Source File: HamletParserDefinition.java From intellij-haskforce with Apache License 2.0 | 4 votes |
@Override public PsiParser createParser(Project project) { return new HamletParser(); }
Example #27
Source File: YangParserDefinition.java From intellij-yang with Apache License 2.0 | 4 votes |
@NotNull public PsiParser createParser(final Project project) { return new YangParser(); }
Example #28
Source File: UnityScriptLanguageVersion.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@Nonnull @Override public PsiParser createParser() { return new EcmaScript4Parser(); }
Example #29
Source File: ShaderLabParserDefinition.java From consulo-unity3d with Apache License 2.0 | 4 votes |
@Nonnull @Override public PsiParser createParser(@Nonnull LanguageVersion languageVersion) { return new ShaderLabParser(); }
Example #30
Source File: BashParserDefinition.java From BashSupport with Apache License 2.0 | 4 votes |
public PsiParser createParser(Project project) { return new BashParser(project, findLanguageLevel(project)); }