Documentation
¶
Overview ¶
Package ebnf lints the grammar files under docs/.
They are Wirth syntax notation rather than ISO 14977, so no ISO tool reads them. golang.org/x/exp/ebnf does: it documents this exact dialect, including the convention that an upper-case name is a nonterminal and a lower-case one is lexical. Parsing and reachability come from there.
What is here is the check no library makes. A quoted terminal has to be text lex turns into exactly one token, so a spelling the grammar invents is an error rather than a rule that could never match.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var GrammarOptions = Options{Start: "File", LexSpellings: true, Annotated: true}
GrammarOptions reads docs/grammar.ebnf.
var NotationOptions = Options{Start: "Grammar"}
NotationOptions reads docs/notation.ebnf, which describes the notation rather than TDL, so its quoted terminals are not TDL tokens.
Functions ¶
func Walk ¶ added in v0.1.8
func Walk(expr ebnf.Expression, fn func(ebnf.Expression))
Walk calls fn on expr and then on everything inside it, in source order.
Types ¶
type Annotations ¶ added in v0.1.3
type Annotations struct {
// Word is the production a generator extracts keywords from.
Word string
// Extras may appear between any two tokens. Each is a name with no
// production, bound by a file-level token directive.
Extras []string
// Tokens maps a name to the pattern the named lex symbol holds.
Tokens map[string]string
// Conflicts are pairs of productions a generator has to consider
// together.
Conflicts [][]string
// Prods holds what is said about each production, by name.
Prods map[string]ProdAnnotations
// contains filtered or unexported fields
}
Annotations are what docs/grammar.ebnf says about itself that the notation cannot: which productions are structure and which are plumbing, where a parser generator needs precedence or has to consider two readings, and which lex symbol defines a name the grammar leaves undefined.
They live in comments, which golang.org/x/exp/ebnf drops, so they are scanned separately and attached by position. See docs/design/treesitter.md.
type File ¶ added in v0.1.3
type File struct {
Grammar ebnf.Grammar
Annotations Annotations
}
A File is a grammar and what its annotations say about it.
type Options ¶
type Options struct {
// Start is the production everything must be reachable from.
Start string
// LexSpellings requires every quoted terminal to be text lex turns
// into exactly one token. It holds for a grammar of TDL and not for a
// grammar of anything else.
LexSpellings bool
// Annotated reads the `/*@ ... */` comments and holds the file to
// them: every production with no expression needs a token binding,
// and every name an annotation mentions has to exist. A grammar
// carrying no annotations is not one of these.
Annotated bool
}
Options say how to read one grammar file.
type ProdAnnotations ¶ added in v0.1.3
type ProdAnnotations struct {
Hidden bool // structure the tree without appearing in it
Inline bool // substitute into callers instead
External bool // a terminal a hand-written scanner produces
Assoc string // "", "left", or "right"
Prec int // meaningful when Assoc is set or Prec is non-zero
HasPrec bool
Token string // the pattern the named lex symbol holds
}
ProdAnnotations are the annotations on one production.