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

[ Forum ] [ Prepackaged Downloads ]

Goldie Home -> Documentation (v0.01/v0.02) -> API Overview


For documentation on a newer version of Goldie, see Documentation For Specific Versions.

Goldie: API Overview


Importing is simple:

import goldie.all;


The primary interface to Goldie is through the static class Goldie. There are also a few other important classes to be aware of: GoldLanguage, GoldLexer, GoldParser, and TokGold.

A trivial program to load a language and parse a file would be like this:

import goldie.all;

void main(char[][] args)
	// Load language
	GoldLanguage lang = Goldie.loadCGT(args[1]);
	// Load and parse source
	GoldParser parser = lang.parseFile(args[2]);
	// Obtain root token of parse tree
	TokGold root = parser.parseTree;

As the code demonstrates, Goldie is first used to load a language contained in a GoldLanguage (it can also infer a language file to load based on the name of a language or the extension of a source file).

The returned GoldLanguage object is then used to parse some given source. (It can take a file, a string, or an array of already-lexed tokens. Also, this GoldLanguage object can be used to obtain all data and metadata within the CGT file.)

The GoldLanguage's parse routines return the actual GoldParser parser object that was used. This GoldParser object can be used to obtain resulting parsing information, the root token (a TokGold) of the resulting parse tree, and the GoldLexer lexer that was used (which can in turn be used to retrieve lexing information).

The root TokGold token can then be used to traverse the resulting parse tree.

If the source fails to successfully parse, in either the lexing or parsing phase, an exception is thrown.

Note, however, that if you wish, it is also possible to manually instantiate and manage GoldParser and GoldLexer objects yourself, instead of using GoldLanguage's interface (But you will still need to use Goldie to load a language which you can then manually pass to your GoldParser and GoldLexer).

Also note that any GoldParser or GoldLexer can be re-used to lex/parse anything else (even a different language).

See Also