ebnf

package
v0.0.0-...-90c9d3a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2010 License: BSD-3-Clause, GooglePatentClause Imports: 7 Imported by: 0

Documentation

Overview

A library for EBNF grammars. The input is text ([]byte) satisfying the following grammar (represented itself in EBNF):

Production  = name "=" Expression "." .
Expression  = Alternative { "|" Alternative } .
Alternative = Term { Term } .
Term        = name | token [ "..." token ] | Group | Option | Repetition .
Group       = "(" Expression ")" .
Option      = "[" Expression "]" .
Repetition  = "{" Expression "}" .

A name is a Go identifier, a token is a Go string, and comments and white space follow the same rules as for the Go language. Production names starting with an uppercase Unicode letter denote non-terminal productions (i.e., productions which allow white-space and comments between tokens); all other production names denote lexical productions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Verify

func Verify(grammar Grammar, start string) os.Error

Verify checks that:

  • all productions used are defined
  • all productions defined are used when beginning at start
  • lexical productions refer only to other lexical productions

Types

type Alternative

type Alternative []Expression // x | y | z

An Alternative node represents a non-empty list of alternative expressions.

func (Alternative) Pos

func (x Alternative) Pos() token.Position

type Expression

type Expression interface {
	// Pos is the position of the first character of the syntactic construct
	Pos() token.Position
}

An Expression node represents a production expression.

type Grammar

type Grammar map[string]*Production

A Grammar is a set of EBNF productions. The map is indexed by production name.

func Parse

func Parse(filename string, src []byte) (Grammar, os.Error)

Parse parses a set of EBNF productions from source src. It returns a set of productions. Errors are reported for incorrect syntax and if a production is declared more than once.

type Group

type Group struct {
	token.Position
	Body Expression // (body)
}

A Group node represents a grouped expression.

type Name

type Name struct {
	token.Position
	String string
}

A Name node represents a production name.

type Option

type Option struct {
	token.Position
	Body Expression // [body]
}

An Option node represents an optional expression.

type Production

type Production struct {
	Name *Name
	Expr Expression
}

A Production node represents an EBNF production.

func (*Production) Pos

func (p *Production) Pos() token.Position

type Range

type Range struct {
	Begin, End *Token // begin ... end
}

A List node represents a range of characters.

func (Range) Pos

func (x Range) Pos() token.Position

type Repetition

type Repetition struct {
	token.Position
	Body Expression // {body}
}

A Repetition node represents a repeated expression.

type Sequence

type Sequence []Expression // x y z

A Sequence node represents a non-empty list of sequential expressions.

func (Sequence) Pos

func (x Sequence) Pos() token.Position

type Token

type Token struct {
	token.Position
	String string
}

A Token node represents a literal.

Jump to

Keyboard shortcuts

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