public interface ParserDefinition
Defines the implementation of a parser for a custom language.
- See Also:
-
LanguageParserDefinitions#forLanguage(Language)
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumRequirements for spacing between tokens. -
Method Summary
Modifier and TypeMethodDescription@NotNull LexercreateLexer(Project project) Returns the lexer for lexing files in the specified project.@NotNull PsiParsercreateParser(Project project) Returns the parser for parsing files in the specified project.@NotNull TokenSetReturns the set of token types which are treated as comments by the PSI builder.@NotNull IFileElementTypeReturns the element type of the node describing a file in the specified language.@NotNull TokenSetReturns the set of element types which are treated as string literals.default @NotNull TokenSetReturns the set of token types which are treated as whitespace by the PSI builder.default @Nullable ASTNodereparseSpace(@NotNull ASTNode originalSpaceNode, @NotNull CharSequence newWhiteSpaceSequence) default @NotNull ParserDefinition.SpaceRequirementsspaceExistenceTypeBetweenTokens(ASTNode left, ASTNode right) Checks if the specified two token types need to be separated by a space according to the language grammar.
-
Method Details
-
createLexer
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
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
Returns the element type of the node describing a file in the specified language.- Returns:
- the file node element type.
-
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
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 examplecom.intellij.psi.impl.source.tree.JavaDocElementType#DOC_COMMENT).- Returns:
- the set of comment token types.
-
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
originalSpaceNodecan be replaced with new one with text fromnewWhiteSpaceSequencefor the language or null. - See Also:
-
com.intellij.lang.ASTFactory#leaf(IElementType, CharSequence)
- API Note:
newWhiteSpaceSequenceis guaranteed to contain onlyspaces. 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.
-