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

Token node types

Last modified: 04 July 2023

Each leaf element in a PSI tree has a node type that is a singleton instance of a class that derives from the TokenNodeType base class, and implements the ITokenNodeType interface. This singleton instance is the token produced by the lexer.

Each language must provide at least one class that derives from TokenNodeType. Typically, this will provide default values for the simple abstract properties. These values can be constants that are overridden in further derived classes (that represent whitespace, comments, etc.) or can be implemented directly by comparing this to known singleton values for comments, whitespace, etc.

Like NodeType, the constructor takes in a string identifier and a unique index for the node type, and passes them to the base class. The identifier is only used internally, for diagnostics and testing, and should be simple enough to identify the node type, e.g. "NEW_LINE", "COMMENT", "IDENTIFIER", etc.

The TokenRepresentation property is a value that is usually passed into the constructor of a derived class, and provides a more human readable representation of the token than the identifier value passed to the constructor of TokenNodeType. For example, the identifier might be "ANDAND", while the representation would be "&&", or "RETURN_KEYWORD" and "return". This is used by the GetSampleText and GetDescription methods.

The GetSampleText method is called by a language's formatter implementation, to see if two token types require whitespace to separate them (by building a string with the two pieces of sample text and attempting to lex it. If it succeeds, no whitespace is necessary). By default, this is the TokenRepresentation.

The GetDescription method returns a human readable description of the token for use in parse errors. Typically, this is the TokenRepresentation abstract method, but if this is null or empty, it returns the string identifier passed to the constructor (e.g. "IDENTIFIER", "NEW_LINE").

The class also provides two Create methods. One which takes a string, and another that takes a string buffer and a start and end offset. These methods are used by the parser to create leaf elements for the tree - LeafElementBase provides an abstract implementation of various parts of ITreeNode.