ReSharper Platform SDK
 
Because ReSharper Platform SDK undefined is still in development, this documentation may not be entirely accurate and is subject to change.

Creating Node Types

Last modified: 04 July 2023

A custom language requires many NodeType classes and instances to be created. After all, every distinct type of node in a PSI tree needs a distinct NodeType instance. While it is possible to create these classes and instances by hand, it is more manageable to use tooling to generate the code.

The SDK provides the TokenGenerator tool to convert an XML file listing tokens and keywords into TokenNodeType classes and static singleton instances. The PsiGen tool is used to create a parser from a .psi file, but it also creates ITreeNode classes and CompositeNodeType classes and instances.

The output of the lexer is a stream of singleton instances of TokenNodeType derived classes. The parser doesn't need to know the actual class of the token node type, it only needs to compare it against a known singleton value, and call a known method - TokenNodeType.Create. The same is true for interior tree nodes - the class of the CompositeNodeType is irrelevant, instead, the known singleton value is used to call CompositeNodeType.Create to create the interior tree node.

As such, the usual structure when creating node types is to create them as private nested classes inside a "token type" or "element type" class, and create public static fields that expose the singleton instance.