ebnf

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package ebnf contains the AST and parser for parsing the form of EBNF produced by Participle.

The self-referential EBNF is:

EBNF = Production* .
Production = <ident> "=" Expression "." .
Expression = Sequence ("|" Sequence)* .
SubExpression = "(" ("?!" | "?=")? Expression ")" .
Sequence = Term+ .
Term = "~"? (<ident> | <string> | ("<" <ident> ">") | SubExpression) ("*" | "+" | "?" | "!")? .

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EBNF

type EBNF struct {
	Productions []*Production `@@*`
}

EBNF itself.

func Parse

func Parse(r io.Reader) (*EBNF, error)

Parse io.Reader into EBNF.

func ParseString

func ParseString(ebnf string) (*EBNF, error)

ParseString string into EBNF.

func (*EBNF) String

func (e *EBNF) String() (out string)

type Expression

type Expression struct {
	Alternatives []*Sequence `@@ ( "|" @@ )*`
}

Expression is a set of alternatives separated by "|" in the EBNF.

func (*Expression) String

func (e *Expression) String() (out string)

type LookaheadAssertion

type LookaheadAssertion rune

LookaheadAssertion enum.

const (
	LookaheadAssertionNone     LookaheadAssertion = 0
	LookaheadAssertionNegative LookaheadAssertion = '!'
	LookaheadAssertionPositive LookaheadAssertion = '='
)

Lookahead assertion enums.

func (*LookaheadAssertion) Capture

func (l *LookaheadAssertion) Capture(tokens []string) error

type Node

type Node interface {
	// contains filtered or unexported methods
}

A Node in the EBNF grammar.

type Production

type Production struct {
	Production string      `@Ident "="`
	Expression *Expression `@@ "."`
}

Production of the grammar.

type Sequence

type Sequence struct {
	Terms []*Term `@@+`
}

A Sequence of terms.

func (*Sequence) String

func (s *Sequence) String() (out string)

type SubExpression

type SubExpression struct {
	Lookahead LookaheadAssertion `"(" ("?" @("!" | "="))?`
	Expr      *Expression        `@@ ")"`
}

SubExpression is an expression inside parentheses ( ... )

func (*SubExpression) String

func (s *SubExpression) String() string

type Term

type Term struct {
	Negation bool `@("~")?`

	Name    string         `(   @Ident`
	Literal string         `  | @String`
	Token   string         `  | "<" @Ident ">"`
	Group   *SubExpression `  | @@ )`

	Repetition string `@("*" | "+" | "?" | "!")?`
}

Term in the EBNF grammar.

func (*Term) String

func (t *Term) String() string

Jump to

Keyboard shortcuts

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