ebnf

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

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

View Source
var GrammarOptions = Options{Start: "File", LexSpellings: true, Annotated: true}

GrammarOptions reads docs/grammar.ebnf.

View Source
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.

func Read added in v0.1.3

func Read(filename, src string, opts Options) (*File, []error)

Read parses a grammar and its annotations, reporting every problem it finds. A file that does not parse returns no grammar and only its parse errors.

func ReadFile added in v0.1.8

func ReadFile(path string, opts Options) (*File, error)

ReadFile is Read over a file on disk, with every problem joined into one error.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL