Interface ParserDefinition


public interface ParserDefinition
Defines the implementation of a parser for a custom language.
See Also:
  • LanguageParserDefinitions#forLanguage(Language)
  • Method Details

    • createLexer

      @NotNull @NotNull Lexer createLexer(Project project)
      Returns the lexer for lexing files in the specified project. This lexer does not need to support incremental relexing - it is always called for the entire file.
      Parameters:
      project - the project to which the lexer is connected.
      Returns:
      the lexer instance.
    • createParser

      @NotNull @NotNull PsiParser createParser(Project project)
      Returns the parser for parsing files in the specified project.
      Parameters:
      project - the project to which the parser is connected.
      Returns:
      the parser instance.
    • getFileNodeType

      @NotNull @NotNull IFileElementType getFileNodeType()
      Returns the element type of the node describing a file in the specified language.
      Returns:
      the file node element type.
    • getWhitespaceTokens

      @NotNull default @NotNull TokenSet getWhitespaceTokens()
      Returns the set of token types which are treated as whitespace by the PSI builder. Tokens of those types are automatically skipped by PsiBuilder. Whitespace elements on the bounds of nodes built by PsiBuilder are automatically excluded from the text range of the nodes.

      It is strongly advised you return TokenSet that only contains TokenType.WHITE_SPACE, which is suitable for all the languages unless you really need to use special whitespace token

      Returns:
      the set of whitespace token types.
    • getCommentTokens

      @NotNull @NotNull TokenSet getCommentTokens()
      Returns the set of token types which are treated as comments by the PSI builder. Tokens of those types are automatically skipped by PsiBuilder. Also, To Do patterns are searched in the text of tokens of those types. For composite comment elements it should contain only the root element type (for example com.intellij.psi.impl.source.tree.JavaDocElementType#DOC_COMMENT).
      Returns:
      the set of comment token types.
    • getStringLiteralElements

      @NotNull @NotNull TokenSet getStringLiteralElements()
      Returns the set of element types which are treated as string literals. "Search in strings" option in refactorings is applied to the contents of such tokens.
      Returns:
      the set of string literal element types.
    • spaceExistenceTypeBetweenTokens

      @NotNull default @NotNull ParserDefinition.SpaceRequirements spaceExistenceTypeBetweenTokens(ASTNode left, ASTNode right)
      Checks if the specified two token types need to be separated by a space according to the language grammar. For example, in Java two keywords are always separated by a space; a keyword and an opening parenthesis may be separated or not separated. This is used for automatic whitespace insertion during AST modification operations.
      Parameters:
      left - the first token to check.
      right - the second token to check.
      Returns:
      the spacing requirements.
    • reparseSpace

      @Experimental @Nullable default @Nullable ASTNode reparseSpace(@NotNull @NotNull ASTNode originalSpaceNode, @NotNull @NotNull CharSequence newWhiteSpaceSequence)
      Returns:
      new node for the white space iff originalSpaceNode can be replaced with new one with text from newWhiteSpaceSequence for the language or null.
      See Also:
      • com.intellij.lang.ASTFactory#leaf(IElementType, CharSequence)
      API Note:
      newWhiteSpaceSequence is guaranteed to contain only spaces. Parser definition is selected by platform using language from parent element of the whitespace. Keep in mind that original space may not only be part of your language file, but in multi-psi file as a part of the templating file, part of the file injected into other element, part of lazy-parseable element in other language, part of derived language. Some of these cases may require additional logic.