Goldie: StaticLang

Goldie
Parsing System (v0.4)
Goldie Home (v0.4)
Getting Started

- Requirements
- Download / Install
- Never Used a Parsing Tool?
- How To Use Goldie
- Grammar Definition Language
- Message Board
- Ticket System

Goldie's Tools

- DumpCGT
- GenDocs
  - Template Format
- GRMC: Grammar Compiler
- JsonViewer
  - Parse Tree Mode
- Parse
- StaticLang
- Other Tools

GoldieLib Overview

- Static And Dynamic Styles
- Ambiguous Symbols

GoldieLib Reference

- Base
- Exception
- class Language
- class Lexer
- class Parser
- struct Symbol
- class Token
- Ver

GoldieLib Sample Apps

- Calculator Dynamic
- Calculator Static
- Parse Anything

CGT File Format
FAQ
Change Log
If You Use Trunk
Future Work
Developers

- Library Source and StaticLang

Goldie Home (v0.4) -> 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 won't change any files, but it will add a few. 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") | | +-- 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:

Sample Usage: 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 Creates "foo/src/myapp/mylang/*.d", each containing "module myapp.mylang.*;" Switches: (Prefixes can be '/', '-' or '--') ('[]' means multiple switches are accepted) -help Displays a help summary and exits -detail Displays a detailed help message and exits <text> (Required) CGT language file to use -pack:<text> Name of output package (default: goldie.staticlang.{cgt}) -dir:<text> Directory of package root (default: current directory)

### See Also:

- Static And Dynamic Styles
- Library Source and StaticLang