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 (v0.01/v0.02) -> API Reference

THIS IS AN OLD VERSION

For up-to-date information: Main Homepage and Documentation

Goldie: API Reference

static class Goldie

The public interface of Goldie is as follows:

public static class Goldie
{
	// Read-Only Property: The version of Goldie in string form (ex. "0.01")
	public static char[] verStr();

	// Read-Only Property: The version of Goldie in Ver form.
	//   Ver is a type defined in semitwist.ver from SemiTwist D Tools
	//   and is useful for comparing versions.
	public static Ver ver();

	// Loads a GOLD CGT file. Ignores langDir.
	// Ex: Goldie.loadCGT("lang/myLang.cgt")
	public static GoldLanguage loadCGT(char[] filename);

	// Attempts to find a language in langDir and load it
	// Ex: Goldie.loadLanguage("myLang"); // Loads langDir~"myLang.cgt"
	public static GoldLanguage loadLanguage(char[] language);

	// Attempts to infer and load the language of a file (by extension)
	// Ex: Goldie.loadLanguageOf("mySource.myLang"); // Loads langDir~"myLang.cgt"
	public static GoldLanguage loadLanguageOf(char[] sourceFilename);

	// Utility function: "myLang" -> langDir~"myLang.cgt"
	public static char[] getLanguageFilename(char[] language);

	// Utility function: "mySource.myLang" -> langDir~"myLang.cgt"
	public static char[] inferLanguageFilenameOf(char[] sourceFilename);

	// Utility function: "mySource.myLang" -> "myLang"
	public static char[] inferLanguageOf(char[] sourceFilename);

	// The directory from which Goldie will attempt to load languages.
	// Default is "lang/"
	public static char[] langDir;
}

class GoldLanguage

The public interface of GoldLanguage is as follows:

public class GoldLanguage
{
	// Information from CGT
	public wchar[] name;
	public wchar[] ver;
	public wchar[] author;
	public wchar[] about;
	public bool    caseSensitive;
	public char[]  filename;
	
	// Information from CGT
	public GoldSymbol[]    symbolTable;
	public GoldCharSet[]   characterSetTable;
	public GoldRule[]      ruleTable;
	public GoldDFAState[]  dfaTable;
	public GoldLALRState[] lalrTable;
	
	// Information from CGT
	public int startSymbolIndex;
	public int initialDFAState;
	public int initialLALRState;
	
	// Information from CGT
	public int eofSymbolIndex;
	public int errorSymbolIndex;

	// Property: Actual GoldSymbol referred to by eofSymbolIndex and errorSymbolIndex
	public GoldSymbol eofSymbol();
	public GoldSymbol errorSymbol();

	// Send debugging info to stdout when loading a CGT
	public static bool outputDebugInfo=false;
	
	// Usually just called by the Goldie.parse*() functions
	public GoldLexer lexFile(char[] filename);
	public GoldLexer lexCode(char[] source, char[] filename="");
	
	// Usually just called by the Goldie.parse*() functions
	public GoldParser parseTokens(TokGold[] tokens, char[] filename="", GoldLexer lexerUsed=null);
	public GoldParser parseFile(char[] filename);
	public GoldParser parseCode(char[] source, char[] filename="");
}

class TokGold

The public interface of TokGold is as follows:

public class TokGold
{
	// 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
}

More…

(Info on more classes to come...)

See Also