Java Code Examples for com.intellij.lang.PsiParser

The following are top voted examples for showing how to use com.intellij.lang.PsiParser. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: intellij-ce-playground   File: SPIParserDefinition.java   Source Code and License 6 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
  return new PsiParser() {
    @NotNull
    @Override
    public ASTNode parse(IElementType root, PsiBuilder builder) {
      final PsiBuilder.Marker rootMarker = builder.mark();
      final PsiBuilder.Marker propertiesList = builder.mark();
      while (!builder.eof()) {
        parseProvider(builder);
      }
      propertiesList.done(SPIElementTypes.PROVIDERS_LIST);
      rootMarker.done(root);
      return builder.getTreeBuilt();
    }
  };
}
 
Example 2
Project: intellij   File: BuildParserTest.java   Source Code and License 6 votes vote down vote up
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
Project: tools-idea   File: SPIParserDefinition.java   Source Code and License 6 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
  return new PsiParser() {
    @NotNull
    @Override
    public ASTNode parse(IElementType root, PsiBuilder builder) {
      final PsiBuilder.Marker rootMarker = builder.mark();
      final PsiBuilder.Marker propertiesList = builder.mark();
      while (!builder.eof()) {
        parseProvider(builder);
      }
      propertiesList.done(SPIElementTypes.PROVIDERS_LIST);
      rootMarker.done(root);
      return builder.getTreeBuilt();
    }
  };
}
 
Example 4
Project: intellij-ce-playground   File: DTDParserDefinition.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public PsiParser createParser(Project project) {
  return new PsiParser() {
    @NotNull
    @Override
    public ASTNode parse(IElementType root, PsiBuilder builder) {
      return new DtdParsing(root, XmlEntityDecl.EntityContextType.GENERIC_XML, builder).parse();
    }
  };
}
 
Example 5
Project: intellij   File: ProjectViewParserDefinition.java   Source Code and License 5 votes vote down vote up
@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 6
Project: epigraph   File: EpigraphPsiUtil.java   Source Code and License 5 votes vote down vote up
public static @NotNull <T extends PsiElement> T parseText(
    @NotNull String text,
    @NotNull IElementType rootElementType,
    @NotNull Class<T> rootElementClass,
    @NotNull ParserDefinition parserDefinition,
    @Nullable ErrorProcessor errorProcessor) {

  LanguageParserDefinitions.INSTANCE.addExplicitExtension(
      parserDefinition.getFileNodeType().getLanguage(),
      parserDefinition
  );

  PsiParser parser = parserDefinition.createParser(model.first);
  Lexer lexer = parserDefinition.createLexer(model.first);
  PsiBuilderImpl psiBuilder = new PsiBuilderImpl(
      model.first,
      null,
      parserDefinition,
      lexer,
      new CharTableImpl(),
      text,
      null,
      null
  );

  ASTNode astNode = parser.parse(rootElementType, psiBuilder);
  T res = astNode.getPsi(rootElementClass);
  collectErrors(res, errorProcessor);

  return res;
}
 
Example 7
Project: js-graphql-intellij-plugin   File: JSGraphQLParserDefinition.java   Source Code and License 5 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    if(project != null) {
        project.putUserData(JSGRAPHQL_ACTIVATED, true);
    }
    return new JSGraphQLParser();
}
 
Example 8
Project: idea-multimarkdown   File: MultiMarkdownParserDefinition.java   Source Code and License 5 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    //return new MultiMarkdownParser();
    return MultiMarkdownGlobalSettings.getInstance().lightParserFailedBuild.runBuild(new FailedBuildRunnable<PsiParser>() {
        @Nullable @Override public PsiParser runCanFail() throws Throwable {
            return new MultiMarkdownLightParser();
        }

        @Nullable @Override public PsiParser run() {
            return new MultiMarkdownParser();
        }
    });
}
 
Example 9
Project: intellij-haskforce   File: HaskellParserUtilBase.java   Source Code and License 5 votes vote down vote up
/**
 * 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 10
Project: intellij-haskforce   File: HaskellParserUtilBase.java   Source Code and License 5 votes vote down vote up
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 11
Project: tools-idea   File: DTDParserDefinition.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public PsiParser createParser(Project project) {
  return new PsiParser() {
    @NotNull
    @Override
    public ASTNode parse(IElementType root, PsiBuilder builder) {
      return new DtdParsing(root, XmlEntityDecl.EntityContextType.GENERIC_XML, builder).parse();
    }
  };
}
 
Example 12
Project: consulo-csharp   File: CSharpPreprocessorElements.java   Source Code and License 5 votes vote down vote up
@Override
protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull 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 13
Project: consulo-csharp   File: CSharpDocElements.java   Source Code and License 5 votes vote down vote up
@Override
@RequiredReadAction
protected ASTNode doParseContents(@NotNull final ASTNode chameleon, @NotNull 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 14
Project: consulo-javaee   File: JspJavaFileElementType.java   Source Code and License 5 votes vote down vote up
@NotNull
private PsiBuilder doParse(@NotNull ASTNode chameleon, Project project, LanguageVersion languageVersion)
{
	LanguageLevel languageLevel = LanguageLevel.HIGHEST;
	PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new JspJavaLexer(languageLevel), JavaLanguage.INSTANCE, languageVersion, chameleon.getChars());
	JavaParserUtil.setLanguageLevel(builder, languageLevel);
	PsiParser parser = new JavaInJspParser();
	parser.parse(this, builder, languageVersion);
	return builder;
}
 
Example 15
Project: consulo-dotnet   File: BaseExpressionCfsLanguageVersion.java   Source Code and License 5 votes vote down vote up
@NotNull
@Override
public PsiParser createParser()
{
	if(myExpressionElementType == null)
	{
		myExpressionElementType = createExpressionElementType();
	}
	return new CfsParser(myExpressionElementType);
}
 
Example 16
Project: consulo   File: LanguageVersionableParserDefinition.java   Source Code and License 5 votes vote down vote up
@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 17
Project: TS-IJ   File: TSParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new TSParser();
}
 
Example 18
Project: AppleScript-IDEA   File: AppleScriptParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
  return new AppleScriptParser();
}
 
Example 19
Project: reasonml-idea-plugin   File: RmlParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new RmlParser();
}
 
Example 20
Project: reasonml-idea-plugin   File: OclP4ParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new OclParser();
}
 
Example 21
Project: reasonml-idea-plugin   File: OclParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new OclParser();
}
 
Example 22
Project: greycat-idea-plugin   File: GCMParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new GCMParser();
}
 
Example 23
Project: bamboo-soy   File: SoyParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
  return new SoyParser();
}
 
Example 24
Project: EmojiPrefix   File: EmojiResourceParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
	return new EmojiResourceParser();
}
 
Example 25
Project: hybris-integration-intellij-idea-plugin   File: FlexibleSearchParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new FlexibleSearchParser();
}
 
Example 26
Project: hybris-integration-intellij-idea-plugin   File: ImpexParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
@Override
public PsiParser createParser(final Project project) {
    return new ImpexParser();
}
 
Example 27
Project: idea-onescript   File: OneScriptParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new OneScriptParser();
}
 
Example 28
Project: intellij-csv-validator   File: CsvParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
@NotNull
public PsiParser createParser(final Project project) {
    return new CsvParser();
}
 
Example 29
Project: Goal-Intellij-Plugin   File: ActionSpecParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new ActionSpecParser();
}
 
Example 30
Project: Goal-Intellij-Plugin   File: PrologParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new PrologParser();
}
 
Example 31
Project: Goal-Intellij-Plugin   File: ModuleParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new ModuleParser();
}
 
Example 32
Project: Goal-Intellij-Plugin   File: MasParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new MasParser();
}
 
Example 33
Project: Goal-Intellij-Plugin   File: TestParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new TestParser();
}
 
Example 34
Project: mule-intellij-plugins   File: RamlParserDefinition.java   Source Code and License 4 votes vote down vote up
@Nullable
public PsiParser createParser(final Project project)
{
    return new YAMLParser();
}
 
Example 35
Project: mule-intellij-plugins   File: MelParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new MelParser();
}
 
Example 36
Project: mule-intellij-plugins   File: WeaveParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new WeaveParser();
}
 
Example 37
Project: nix-idea   File: NixParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new NixParser();
}
 
Example 38
Project: sutr-io   File: SutrParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(final Project project) {
    return new SutrParser();
}
 
Example 39
Project: sutr-io   File: UtrParserDefinition.java   Source Code and License 4 votes vote down vote up
@Override
public PsiParser createParser(final Project project) {
    return new UtrParser();
}
 
Example 40
Project: smcplugin   File: SmcParserDefinition.java   Source Code and License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new SmcParser();
}