ast

package
v0.0.0-...-ef17ad3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package ast declares the types used to represent syntax trees for pg.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(v Visitor, node Node)

Walk traverses an AST in depth-first order: It starts by calling v(node); node must not be nil. If v returns true, Walk invokes v recursively for each of the non-nil children of node, followed by a call of v(nil).

Types

type Alternative

type Alternative []Expression

Alternative represents a list of alternative expressions.

func (Alternative) Pos

func (a Alternative) Pos() token.Pos

Pos returns the position of the first character of the expression.

type Epsilon

type Epsilon struct {
	Epsilon string    // epsilon keyword
	Start   token.Pos // position of e or ε
}

Epsilon represents the epsilon keyword.

func (*Epsilon) Pos

func (e *Epsilon) Pos() token.Pos

Pos returns the position of the first character of the expression.

type Expression

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

Expression represents a production expression.

type Grammar

type Grammar []*Production

Grammar represents a set of EBNF productions.

func (Grammar) Pos

func (g Grammar) Pos() token.Pos

Pos returns the position of the first character of the expression.

type Name

type Name struct {
	Name     string    // name of the production
	StartPos token.Pos // position of the first character
}

Name represents a production name.

func (*Name) Pos

func (n *Name) Pos() token.Pos

Pos returns the position of the first character of the expression.

type Node

type Node interface {
	// Pos returns the position of the first character of the expression.
	Pos() token.Pos
	// contains filtered or unexported methods
}

Node is an element in the abstract syntax tree.

type Production

type Production struct {
	Name *Name      // name of the production (lhs)
	Expr Expression // expression of the production (rhs)
}

Production represents a single EBNF production.

func (*Production) Pos

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

Pos returns the position of the first character of the expression.

type Sequence

type Sequence []Expression

Sequence represents a list of sequential expressions.

func (Sequence) Pos

func (s Sequence) Pos() token.Pos

Pos returns the position of the first character of the expression.

type Terminal

type Terminal struct {
	Terminal string    // terminal literal
	QuotePos token.Pos // position of "
}

Terminal represents a terminal.

func (*Terminal) Pos

func (t *Terminal) Pos() token.Pos

Pos returns the position of the first character of the expression.

type Visitor

type Visitor func(Node) bool

Visitor represents a function to be called for each node during a Walk. Walking stops if the visitor returns false.

Jump to

Keyboard shortcuts

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