Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

[ Forum ] [ Prepackaged Downloads ]

Goldie Home -> Documentation -> API Reference -> class Token

Goldie: API Reference: class Token

Public API

public class Token
{
	// Read-Only Properties
	public int line();
	public char[] file();
	public int srcIndexStart();   // Index into original source where this token starts
	public int srcIndexEnd();     // Index into original source where this token ends (exclusive)
	public int srcLength();       // srcIndexStart - srcIndexEnd
	public TokGold firstLeaf();   // Returns first Terminal subtoken (Only useful for NonTerminals)
	public TokGold lastLeaf();    // Returns last Terminal subtoken (Only useful for NonTerminals)
	public GoldSymbolType type(); // Ex: GoldSymbolType.NonTerminal
	public char[] typeName();     // Ex: "NonTerminal"
	public wchar[] name();        // Ex: "Expression"
	public wchar[] fullName();    // Ex: "NonTerminal.Expression"
	public int id();              // id of 'name', not of 'this'
	public char[] debugInfo();

	// Tells whether or not the token was found within a block comment
	// or line comment and is ignored by the parser.
	public GoldCommentType commentMode();

	// Terminals only
	public this(GoldSymbol symbol, char[] content,
	            char[] file="{unknown}", int line=1,
	            int srcIndexStart=0, int srcIndexEnd=0,
	            GoldCommentType commentMode=GoldCommentType.None,
	            char[] debugInfo="");
	
	// NonTerminals only
	public this(GoldSymbol symbol, TokGold[] subTokens);

	// Only useful for NonTerminals:
	//   this.length: Number of subtokens
	//   this[i]: Subtoken #i
	//   this[i..j]: Slice of subtokens
	//   foreach(          TokGold subtoken; this) {}
	//   foreach(   int i, TokGold subtoken; this) {}
	//   foreach(size_t i, TokGold subtoken; this) {}
	//   foreach_reverse(...; this) {}
	public size_t length();
	public TokGold opIndex(size_t i);
	public TokGold[] opSlice();
	public TokGold[] opSlice(size_t i1, size_t i2);
	public int opApply(int delegate(ref size_t, ref TokGold) dg);
	public int opApply(int delegate(ref int, ref TokGold) dg);
	public int opApply(int delegate(ref TokGold) dg);
	public int opApplyReverse(int delegate(ref size_t, ref TokGold) dg);
	public int opApplyReverse(int delegate(ref int, ref TokGold) dg);
	public int opApplyReverse(int delegate(ref TokGold) dg);

	public char[] toString(); // Excludes designated whitespace and comments
	public TreeNode toTreeNode(size_t index=0); // From SemiTwist D Tools: module semitwist.treeout
}

See Also