Java Code Examples for com.intellij.lang.PsiBuilder#getTreeBuilt()

The following examples show how to use com.intellij.lang.PsiBuilder#getTreeBuilt() . 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 vote down vote up
@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: CSharpPreprocessorParser.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ASTNode parse(@Nonnull IElementType elementType, @Nonnull PsiBuilder builder, @Nonnull LanguageVersion languageVersion)
{
	PsiBuilder.Marker mark = builder.mark();

	while(!builder.eof())
	{
		PreprocessorParsing.parse(builder);
	}

	mark.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 3
Source File: CSharpFragmentFactory.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: CSharpParser.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ASTNode parse(@Nonnull IElementType elementType, @Nonnull PsiBuilder builder, @Nonnull LanguageVersion languageVersion)
{
	builder.setDebugMode(ApplicationProperties.isInSandbox());

	CSharpBuilderWrapper builderWrapper = new CSharpBuilderWrapper(builder, languageVersion);

	PsiBuilder.Marker marker = builderWrapper.mark();

	DeclarationParsing.parseAll(builderWrapper, true, false);

	marker.done(elementType);
	return builder.getTreeBuilt();
}
 
Example 5
Source File: PrattParser.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public final ASTNode parse(@Nonnull final IElementType root, @Nonnull final PsiBuilder builder, @Nonnull LanguageVersion languageVersion) {
  final PrattBuilder prattBuilder = PrattBuilderImpl.createBuilder(builder, getRegistry());
  final MutableMarker marker = prattBuilder.mark();
  parse(prattBuilder);
  marker.finish(root);
  return builder.getTreeBuilt();
}
 
Example 6
Source File: BuildParserDefinition.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
  if (debug.getValue()) {
    System.err.println(builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY));
  }
  PsiBuilder.Marker rootMarker = builder.mark();
  ParsingContext context = new ParsingContext(builder);
  context.statementParser.parseFileInput();
  rootMarker.done(root);
  return builder.getTreeBuilt();
}
 
Example 7
Source File: SQFParser.java    From arma-intellij-plugin with MIT License 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 8
Source File: NASMParser.java    From JetBrains-NASM-Language with MIT License 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 9
Source File: BuckParser.java    From Buck-IntelliJ-Plugin with Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 10
Source File: RTParser.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
    new RTJSParser(builder).parseRT(root);
    return builder.getTreeBuilt();
}
 
Example 11
Source File: ThriftParser.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 12
Source File: SimpleParser.java    From intellij-sdk-docs with Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 13
Source File: JSGraphQLEndpointParser.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
public ASTNode parse(IElementType root_, PsiBuilder builder_) {
  parseLight(root_, builder_);
  return builder_.getTreeBuilt();
}
 
Example 14
Source File: RTParser.java    From react-templates-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
    new RTJSParser(builder).parseRT(root);
    return builder.getTreeBuilt();
}
 
Example 15
Source File: ANTLRParserAdaptor.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@NotNull
@Override
public ASTNode parse(IElementType root, PsiBuilder builder) {
	ProgressIndicatorProvider.checkCanceled();

	TokenSource source = new PSITokenSource(builder);
	TokenStream tokens = new CommonTokenStream(source);
	parser.setTokenStream(tokens);
	parser.setErrorHandler(new ErrorStrategyAdaptor()); // tweaks missing tokens
	parser.removeErrorListeners();
	parser.addErrorListener(new SyntaxErrorListener()); // trap errors
	ParseTree parseTree = null;
	PsiBuilder.Marker rollbackMarker = builder.mark();
	try {
		parseTree = parse(parser, root);
	}
	finally {
		rollbackMarker.rollbackTo();
	}

	// Now convert ANTLR parser tree to PSI tree by mimicking subtree
	// enter/exit with mark/done calls. I *think* this creates their parse
	// tree (AST as they call it) when you call {@link PsiBuilder#getTreeBuilt}
	ANTLRParseTreeToPSIConverter listener = createListener(parser, root, builder);
	PsiBuilder.Marker rootMarker = builder.mark();
	ParseTreeWalker.DEFAULT.walk(listener, parseTree);
	while (!builder.eof()) {
		ProgressIndicatorProvider.checkCanceled();
		builder.advanceLexer();
	}
	// NOTE: parse tree returned from parse will be the
	// usual ANTLR tree ANTLRParseTreeToPSIConverter will
	// convert that to the analogous jetbrains AST nodes
	// When parsing an entire file, the root IElementType
	// will be a IFileElementType.
	//
	// When trying to rename IDs and so on, you get a
	// dummy root and a type arg identifier IElementType.
	// This results in a weird tree that has for example
	// (ID (expr (primary ID))) with the ID IElementType
	// as a subtree root as well as the appropriate leaf
	// all the way at the bottom.  The dummy ID root is a
	// CompositeElement and created by
	// ParserDefinition.createElement() despite having
	// being TokenIElementType.
	rootMarker.done(root);
	return builder.getTreeBuilt(); // calls the ASTFactory.createComposite() etc...
}
 
Example 16
Source File: CppParserDefinition.java    From CppTools with Apache License 2.0 4 votes vote down vote up
@NotNull
public ASTNode parse(IElementType iElementType, PsiBuilder psiBuilder) {
  final PsiBuilder.Marker rootMarker = psiBuilder.mark();
  final LinkedList<BlockInfo> blocks = new LinkedList<BlockInfo>();
  boolean openBlock = true;

  while (psiBuilder.getTokenType() != null) {
    if (openBlock) {
      final IElementType type = psiBuilder.getTokenType();
      if (type != CppTokenTypes.RBRACE && type != CppTokenTypes.SEMICOLON && type != CppTokenTypes.COMMA &&
        type != CppTokenTypes.LBRACE && (type != CppTokenTypes.PRE_KEYWORD || !psiBuilder.getTokenText().equals("\\"))) {
        openBlock = false;
        blocks.add(new BlockInfo(psiBuilder.mark(), blocks.size() > 0 ? BlockInfo.BlockType.STATEMENT : BlockInfo.BlockType.FUNC));
      }
    }

    final IElementType tokenType = psiBuilder.getTokenType();

    if (tokenType == CppTokenTypes.LBRACE) {
      blocks.add(new BlockInfo(psiBuilder.mark(), BlockInfo.BlockType.BLOCK));
    } else if (tokenType == CppTokenTypes.LPAR || tokenType == CppTokenTypes.LBRACKET) {
      if (blocks.size() > 0) blocks.getLast().addParens(psiBuilder.mark());
    }

    final PsiBuilder.Marker tokenMarker = requiresComposite(tokenType) ? psiBuilder.mark():null;
    psiBuilder.advanceLexer();
    if (tokenMarker != null) tokenMarker.done(tokenType);

    if (tokenType == CppTokenTypes.LBRACE) {
      openBlock = true;
    } else if (tokenType == CppTokenTypes.RPAR || tokenType == CppTokenTypes.RBRACKET) {
      if (blocks.size() > 0) blocks.getLast().doneParens();
    } else if (tokenType == CppTokenTypes.RBRACE && blocks.size() > 0) {
      blocks.removeLast().done();
      if (blocks.size() > 0) blocks.removeLast().done();
      openBlock = true;
    }
    else if (tokenType == CppTokenTypes.SEMICOLON && blocks.size() > 0 && !blocks.getLast().hasParens() && !openBlock) {
      blocks.removeLast().done();
      openBlock = true;
    }
  }

  while(blocks.size() > 0) {
    blocks.removeLast().done();
  }
  rootMarker.done(iElementType);
  return psiBuilder.getTreeBuilt();
}
 
Example 17
Source File: NixParser.java    From nix-idea with Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 18
Source File: ConceptParser.java    From Intellij-Plugin with Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
    parseLight(t, b);
    return b.getTreeBuilt();
}
 
Example 19
Source File: MelParser.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}
 
Example 20
Source File: HaskellParser.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
public ASTNode parse(IElementType t, PsiBuilder b) {
  parseLight(t, b);
  return b.getTreeBuilt();
}