Documentation ¶
Overview ¶
Package glean contains useful utilities for parser generators.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScanDir ¶
ScanDir searches for grammar rules in the .go files in a directory
Files named *_test.go are ignored. For each rule found, rules.AddRule is called. All the files must belong to the same package; the name of that package is the first returned value.
Types ¶
type Grammar ¶
type Grammar interface { RuleAdder ParserWriter }
A Grammar can accumulate rules and write a parser.
type ParserWriter ¶
type ParserWriter interface { // ParserWriter writes a grammar parser in Go. // // Typically, the caller will write the result into a .go file, // with a comment marking the file as automatically generated. // // The goal argument is the goal symbol that will be the result // of the parse. The parse function will have the signature // // func ([]interface{}) (goal, error) // // The packname argument is copied to the package statment in the // generated code. The prefix is prepended to the names of all // file-level identifiers; in particular the name of the main // parse function will be prefix + "Parse". WriteParser(goal, packname, prefix string) (string, error) }
A ParserWriter can write a parser (in Go) for a grammar.
type RuleAdder ¶
type RuleAdder interface { // AddRule adds one rule to the grammar. // // Callers should ensure the same name is never used in two calls // to AddRule. AddRule(name, target string, items []string) error }
A RuleAdder can have grammar rules added to it.
Grammar symbols are represented by arbitrary strings. Each rule has a name, which should be unique.
If the intent is to write a parser for the grammar, then the rule names and symbol strings should be valid Go identifiers.
Directories ¶
Path | Synopsis |
---|---|
Package earley contains an implementation of glean.Grammar using a simple Earley-style parser.
|
Package earley contains an implementation of glean.Grammar using a simple Earley-style parser. |
Glean generates parsers for context-free grammars.
|
Glean generates parsers for context-free grammars. |
Package gleanerrors contains types used to report errors from parsers generated by glean.
|
Package gleanerrors contains types used to report errors from parsers generated by glean. |