Goldie Homepage Documentation (v0.3) |
struct SymbolSee the explanation of Tokens vs Symbols. module goldie.base NonTerminal
Terminal Whitespace EOF CommentStart CommentEnd CommentLine Error EOF and Error symbols (there is exactly one of each in every language) are automatically created by GOLD Parser Builder when a grammar is compiled into a CGT. Symbols of the other SymbolType values are defined by a grammar. (Although, GOLD automatically defines a Whitespace symbol if the grammar doesn't define one manually. See the GOLD documentation for details.) All SymbolType values except for NonTerminal are technically considered to be terminals (and tokens of these symbols are created by the Lexer instead of the Parser), although the actual SymbolType.Terminal value is only used for "normal" terminals (ie., ones that don't match any of the other SymbolType values). module goldie.base string name
The name of the symbol, as defined in a language's grammar. For non-terminals, this includes the surrounding < and >. For example, in a grammar, <If Statement> ::= 'if' would define a non-terminal symbol with a name of <If Statement>.
The type of symbol.
int id
The ID of the symbol. This is an index into
Language.symbolTable.
string toString()
The result of this is valid D code representing a struct literal.
For example:
auto sym = Symbol("foo", SymbolType.Terminal, 7);
// Output: Symbol("foo",SymbolType.Terminal,7)
Stdout.formatln("{}", sym);
module goldie.base
Example:
string str = symbolTypeToString(SymbolType.NonTerminal);
assert(str == "NonTerminal");
Example:
string str = fullSymbolTypeToString(SymbolType.NonTerminal);
assert(str == "SymbolType.NonTerminal");
Example:
auto symTypes = [SymbolType.Terminal, SymbolType.NonTerminal, SymbolType.Terminal];
string str = symbolTypesToString(symTypes);
assert(str == "Terminal, NonTerminal, Terminal");
Example:
auto symTypes = [SymbolType.Terminal, SymbolType.NonTerminal, SymbolType.Terminal];
auto strings = symbolTypesToStrings(symTypes);
assert(strings.length == 3);
assert(strings[0] == "Terminal");
assert(strings[1] == "NonTerminal");
assert(strings[2] == "Terminal");
|