public interface TokenId
Token ids are typically defined as enums by the following pattern:
public enum JavaTokenId implements TokenId { ERROR(null, "error"), IDENTIFIER(null, "identifier"), ABSTRACT("abstract", "keyword"), ... SEMICOLON(";", "separator"), ... private final String fixedText; // Used by lexer for production of flyweight tokens private final String primaryCategory; JavaTokenId(String fixedText, String primaryCategory) { this.fixedText = fixedText; this.primaryCategory = primaryCategory; } public String fixedText() { return fixedText; } public String primaryCategory() { return primaryCategory; } }
Token ids can also be generated (e.g. by lexer generation tools)
by using LanguageHierarchy.newId(String,int,String)
method.
All token ids of a language must have both
unique ordinal and name.
Token name should be all uppercase while token categories should be named
in lowercase.
Detailed information and rules for naming can be found in TokenId Naming.
Modifier and Type | Method and Description |
---|---|
String |
name()
Get name of this tokenId.
|
int |
ordinal()
Get integer identification of this tokenId.
|
String |
primaryCategory()
Get name of primary token category into which this token belongs.
|
String name()
It can serve for several purposes such as finding a possible style information for the given token.
int ordinal()
String primaryCategory()