Documentation
¶
Overview ¶
Package ebnf lints the grammar files under docs/, which are Wirth syntax notation as read by golang.org/x/exp/ebnf. Parsing and reachability come from that library; this package adds the check that every quoted terminal is text lex turns into exactly one token.
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, whose 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 the `/*@ ... */` comments in docs/grammar.ebnf: what a parser generator needs that the notation cannot say. They are scanned separately from the grammar 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.
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.
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.