Java Code Examples for com.intellij.lang.PsiParser

The following examples show how to use com.intellij.lang.PsiParser. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: intellij   Source File: BuildParserTest.java    License: Apache License 2.0 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 2
Source Project: consulo-csharp   Source File: CSharpFileStubElementType.java    License: Apache License 2.0 6 votes vote down vote up
@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 3
Source Project: intellij   Source File: ProjectViewParserDefinition.java    License: Apache License 2.0 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 4
@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 5
Source Project: intellij-haskforce   Source File: HaskellParserUtilBase.java    License: Apache License 2.0 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 6
Source Project: intellij-haskforce   Source File: HaskellParserUtilBase.java    License: Apache License 2.0 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 7
Source Project: consulo-csharp   Source File: CSharpPreprocessorElements.java    License: Apache License 2.0 5 votes vote down vote up
@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 8
Source Project: consulo-csharp   Source File: CSharpDocElements.java    License: Apache License 2.0 5 votes vote down vote up
@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 9
@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 10
Source Project: intellij-jsonnet   Source File: JsonnetParserDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new JsonnetParser();
}
 
Example 11
Source Project: reasonml-idea-plugin   Source File: RmlParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new RmlParser();
}
 
Example 12
Source Project: reasonml-idea-plugin   Source File: OclYaccParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(Project project) {
    return new OclYaccParser();
}
 
Example 13
Source Project: reasonml-idea-plugin   Source File: OclMlgParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(Project project) {
    return new OclParser();
}
 
Example 14
Source Project: reasonml-idea-plugin   Source File: OclP4ParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new OclParser();
}
 
Example 15
Source Project: reasonml-idea-plugin   Source File: OclMllParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(Project project) {
    return new OclParser();
}
 
Example 16
Source Project: reasonml-idea-plugin   Source File: OclParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new OclParser();
}
 
Example 17
Source Project: reasonml-idea-plugin   Source File: DuneParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new DuneParser();
}
 
Example 18
Source Project: idea-php-typo3-plugin   Source File: FluidParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new FluidParser();
}
 
Example 19
Source Project: idea-php-typo3-plugin   Source File: TypoScriptParserDefinition.java    License: MIT License 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
  return new TypoScriptParser();
}
 
Example 20
Source Project: bamboo-soy   Source File: SoyParserDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
  return new SoyParser();
}
 
Example 21
default PsiParser createParser(PsiFile file) {
    return createParser(file.getProject());
}
 
Example 22
@Override
@NotNull
public PsiParser createParser(final Project project) {
    return new CsvParser();
}
 
Example 23
@Override
public PsiParser createParser(@NotNull PsiFile file) {
    return createParser(file.getProject());
}
 
Example 24
@Nullable
public PsiParser createParser(final Project project)
{
    return new YAMLParser();
}
 
Example 25
Source Project: mule-intellij-plugins   Source File: MelParserDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
    return new MelParser();
}
 
Example 26
@Override
public PsiParser createParser(Project project) {
    return new WeaveParser();
}
 
Example 27
Source Project: nix-idea   Source File: NixParserDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
public PsiParser createParser(final Project project) {
    return new NixParser();
}
 
Example 28
@Override
public PsiParser createParser(Project project) {
    return new FusionParser();
}
 
Example 29
Source Project: arma-intellij-plugin   Source File: SQFParserDefinition.java    License: MIT License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
	return new SQFParser();
}
 
Example 30
Source Project: arma-intellij-plugin   Source File: HeaderParserDefinition.java    License: MIT License 4 votes vote down vote up
@Override
public PsiParser createParser(Project project) {
	return new HeaderParser();
}