Documentation
¶
Overview ¶
Package bnf contains parser for BNF metalanguage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotImplemented = errors.New("bnf: not implemented")
View Source
var ErrUnexpectedChar = errors.New("bnf: unexpected character")
Functions ¶
func Visit ¶
func Visit(root Node, f VisitorFunc) error
Visit implements in-order graph traversal procedure.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represent parsing error and contains some context information.
type Expression ¶
type Expression []*Term
Expression is a list of terminals and non-terminals.
func (Expression) Left ¶
func (e Expression) Left() Node
func (Expression) Right ¶
func (e Expression) Right() Node
func (*Expression) String ¶
func (e *Expression) String() string
type List ¶
type List = Expression
type Node ¶
type Node interface { // Get the left child of a node. Left() Node // Get the right child of a node. Right() Node }
Node is a node of binary tree. In each node of a tree there is a token.
type ProductionRule ¶
type ProductionRule struct { Token // Points to lexeme that contains `::=`. Name *Term Stmt Node Expressions []Expression }
ProductionRule is a production rule itself. Actually, it contains several rules for a non-terminal.
func (*ProductionRule) Left ¶
func (r *ProductionRule) Left() Node
func (*ProductionRule) Right ¶
func (r *ProductionRule) Right() Node
func (*ProductionRule) String ¶
func (r *ProductionRule) String() string
type Term ¶
type Term struct { Name []byte Terminal bool // Begin encodes position where token begins. The possition is relative to // begin position of parent token. Begin int // End encodes position where token ends. The position is relateive as well // as in case of begin. End int }
Term represents terminal or non-terminal.
type VisitorFunc ¶
VisitorFunc is a callback type for graph traversing. Its argument is the current node of traversing.
Click to show internal directories.
Click to hide internal directories.