Goldie: StaticLang
Parsing System (v0.9)
Goldie Home (v0.9) -> Goldie's Tools -> StaticLang

StaticLang

Generates a language package from a CGT file that can be embedded directly into a D program and used in either static-style or dynamic-style.

Example:

Suppose you have a program MyApp with a directory structure like this:

MyAppProject | +-- src (all D sources in here) | | | \-- myapp (package "myapp.*") | | | +-- mylang (empty directory) | | | | | \-- | | | \-- main.d ("module myapp.main;") | \-- langs | +-- mylang.grm \-- mylang.cgt (created by either GRMC or GOLD Parser Builder)

And you want to use mylang in static-style (or you want to use it dynamic-style but have it built directly into MyApp instead of loading the CGT at runtime).

Run this command from the MyAppProject directory:

>goldie-staticlang langs/mylang.cgt --dir=src --pack=myapp.mylang

StaticLang will create some *.d files inside src/myapp/mylang/. So now your project looks like this:

MyAppProject | +-- src (all D sources in here) | | | \-- myapp (package "myapp.*") | | | +-- mylang (package "myapp.mylang.*") | | | | | +-- all.d (module "myapp.mylang.all") | | +-- lang.d (module "myapp.mylang.lang") | | +-- langHelper.d (module "myapp.mylang.langHelper") | | +-- lexer.d (module "myapp.mylang.lexer") | | +-- parser.d (module "myapp.mylang.parser") | | \-- token.d (module "myapp.mylang.token") | | | \-- main.d (module "myapp.main") | \-- langs | +-- mylang.grm \-- mylang.cgt (created by either GRMC or GOLD Parser Builder)

Then, to use the language (in either static-style or dynamic-style), include these lines in src/myapp/main.d:

import goldie.all; import myapp.mylang.all;

And then use the Language_{languageName} named language_mylang, like this:

module myapp; import goldie.all; import myapp.mylang.all; void main() { auto source = "...source code in 'mylang' language here..."; // Static-style: auto rootTokenStatic = language_mylang.parseCode(src).parseTree; // Dynamic-style: auto rootTokenDynamic = language_mylang.parseCodeX(src).parseTreeX; // rootTokenStatic is of type: Token_mylang!"<mylang's start symbol>" // (Look up 'Token_{languageName}!{symbol}' in Goldie's API Reference) // rootTokenDynamic is of type: Token }

You can also use parseFile and parseFileX if you want to parse a file instead of just a string.

For an example of actually using the resulting parse tree, see the source code for the GoldieLib Sample Apps and the examples on the Static And Dynamic Styles page.

If later on you change the mylang grammar, just recompile it to CGT with GRMC: Grammar Compiler or GOLD Parser Builder, and then re-run the StaticLang command above.

Command-line parameters:

Usage: goldie-staticlang [options] cgt-file [options] Examples: goldie-staticlang langs/lang.cgt Creates "goldie/staticlang/lang/*.d", each containing "module goldie.staticlang.lang.*;" goldie-staticlang langs/lang.cgt --dir foo/src --pack myapp.mylang goldie-staticlang langs/lang.cgt --dir=foo/src --pack=myapp.mylang Creates "foo/src/myapp/mylang/*.d", each containing "module myapp.mylang.*;" --help, /? Displays this help screen -p, --pack <name> Name of output package (default: goldie.staticlang.{cgt}) -d, --dir <dir> Directory of package root (default: current directory)

See Also: