Enhanced C#
Language of your choice: library documentation
|
Represents a symbol, which is a singleton string that supports fast comparisons and extensible enums. More...
Represents a symbol, which is a singleton string that supports fast comparisons and extensible enums.
Call GSymbol.Get() to create a Symbol from a string, or GSymbol.GetIfExists() to find a Symbol that has already been created.
Symbols can be used like a global, extensible enumeration. Comparing symbols is as fast as comparing two integers; this is because '==' is not overloaded–equality is defined as reference equality, as there is only one instance of a given Symbol.
Symbols can also be produced in namespaces called "pools". Two Symbols with the same name, but in different pools, are considered to be different symbols. Using a derived class D of Symbol and a SymbolPool<D>, you can make Symbols that are as type-safe as enums.
A Symbol's ToString() function formerly returned the symbol name prefixed with a colon (:), following the convention of the Ruby language, from which I got the idea of Symbols in the first place. However, since Symbols are commonly used for extensible enums, I decided it was better that ToString() return just the Name alone, which makes Symbol more suitable as a drop-in replacement for enums.
Symbols are also useful in compilers and Loyc trees, where there may be a performance advantage in comparing identifiers by reference rather than character-by-character.
Properties | |
string | Name [get] |
Gets the name of the Symbol. More... | |
SymbolPool | Pool [get] |
Gets the SymbolPool in which this Symbol was created. More... | |
bool | IsGlobal [get] |
Returns true if this symbol is in the global pool (GSymbol.Pool). More... | |
int | Id [get] |
Returns a numeric ID for the Symbol. More... | |
Public Member Functions | |
override string | ToString () |
override int | GetHashCode () |
override bool | Equals (object b) |
bool | Equals (Symbol b) |
int | CompareTo (Symbol other) |
Static Public Member Functions | |
static | operator Symbol (string s) |
static | operator string (Symbol s) |
static | operator Symbol (UString s) |
static | operator UString (Symbol s) |
static Symbol | For (string s) |
Alias for GSymbol.Get(string). This function was introduced to match the equivalent ES6 API Symbol.for("string") More... | |
Protected Member Functions | |
Symbol (Symbol prototype) | |
For use by a derived class to produce a statically-typed enumeration in a private pool. See the example under SymbolPool (of SymbolEnum) More... | |
|
inlineprotected |
For use by a derived class to produce a statically-typed enumeration in a private pool. See the example under SymbolPool (of SymbolEnum)
prototype | A strictly temporary Symbol that is used to initialize this object. The derived class should discard the prototype after calling this constructor. |
|
inlinestatic |
Alias for GSymbol.Get(string). This function was introduced to match the equivalent ES6 API Symbol.for("string")
|
get |
Returns a numeric ID for the Symbol.
Normally the Id is auto-assigned and the Id corresponding to a particular Name may vary between different runs of the same program. However, SymbolPool.Get(string, int) can be used to assign a specific Id to a Name when setting up a new pool.
|
get |
Returns true if this symbol is in the global pool (GSymbol.Pool).
|
get |
Gets the name of the Symbol.
Referenced by Loyc.Syntax.CallNode.CallsMin(), Loyc.LLParserGenerator.RuleRef.ChooseGotoLabel(), Loyc.LLParserGenerator.CodeGenHelperBase.ErrorBranch(), Loyc.LLPG.Macros.LLLPG_lexer(), Loyc.LLPG.Macros.LLLPG_parser(), Loyc.Localize.Passthrough(), Loyc.Syntax.Les.Les2PrecedenceMap.ResemblesSuffixOperator(), Loyc.Syntax.LiteralHandlerTable.TryParse(), and Loyc.Localize.UseResourceManager().
|
get |
Gets the SymbolPool in which this Symbol was created.