parser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2020 License: Apache-2.0 Imports: 7 Imported by: 7

Documentation

Index

Constants

View Source
const NoTag = Tag("")

Variables

This section is empty.

Functions

func AssertEqualNodes

func AssertEqualNodes(t *testing.T, v, u Node) bool

func ForEach

func ForEach(iter Iter, fn func(node BaseNode))

func PtrAssign

func PtrAssign(output, input interface{})

Types

type BaseNode

type BaseNode interface {
	Tag() Tag
	// contains filtered or unexported methods
}

func AtIndex

func AtIndex(nodes []BaseNode, ofType reflect.Type, tag Tag, index int) BaseNode

type Foo

type Foo struct{ Terminal }

type Func

type Func func(input *Scanner, output interface{}) error

func (Func) Parse

func (f Func) Parse(input *Scanner, output interface{}) error

type Iter

type Iter interface {
	Next() BaseNode
}

func NewIter

func NewIter(nodes []BaseNode, ofType reflect.Type, tag Tag) Iter

type Node

type Node struct {
	Tag      string        `json:"tag"`
	Extra    interface{}   `json:"extra"`
	Children []interface{} `json:"nodes"`
}

func NewNode

func NewNode(tag string, extra interface{}, children ...interface{}) *Node

func (Node) Count

func (n Node) Count() int

func (Node) Format

func (n Node) Format(state fmt.State, c rune)

func (Node) Get

func (n Node) Get(path ...int) interface{}

func (Node) GetNode

func (n Node) GetNode(path ...int) Node

func (Node) GetScanner

func (n Node) GetScanner(path ...int) Scanner

func (Node) GetString

func (n Node) GetString(path ...int) string

func (Node) String

func (n Node) String() string

type NodeDiff

type NodeDiff struct {
	A, B     *Node
	Children map[int]NodeDiff
	Types    map[int][2]reflect.Type
}

func NewNodeDiff

func NewNodeDiff(a, b *Node) NodeDiff

func (NodeDiff) Equal

func (d NodeDiff) Equal() bool

func (NodeDiff) String

func (d NodeDiff) String() string

type NonTerminal

type NonTerminal struct {
	// contains filtered or unexported fields
}

func (*NonTerminal) Add

func (t *NonTerminal) Add(child ...BaseNode)

func (*NonTerminal) AddAndCount

func (t *NonTerminal) AddAndCount(child BaseNode, dest *int)

func (*NonTerminal) AddAndSet

func (t *NonTerminal) AddAndSet(child BaseNode, dest *BaseNode)

func (*NonTerminal) AllChildren

func (t *NonTerminal) AllChildren() []BaseNode

func (*NonTerminal) AtIndex

func (t *NonTerminal) AtIndex(ofType reflect.Type, tag Tag, index int) BaseNode

func (*NonTerminal) Count

func (t *NonTerminal) Count() int

func (*NonTerminal) Iter

func (t *NonTerminal) Iter(ofType reflect.Type, tag Tag) Iter

func (*NonTerminal) Tag

func (t *NonTerminal) Tag() Tag

type Parser

type Parser interface {
	Parse(input *Scanner, output interface{}) error
}

func Transform

func Transform(parser Parser, transform func(Node) Node) Parser

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewBareScanner added in v0.2.0

func NewBareScanner(offset int, slice string) *Scanner

func NewScanner

func NewScanner(src string) *Scanner

func NewScannerAt

func NewScannerAt(src string, offset, size int) *Scanner

func (Scanner) Context

func (r Scanner) Context() string

func (*Scanner) Eat

func (r *Scanner) Eat(i int, eaten *Scanner) *Scanner

func (*Scanner) EatRegexp

func (r *Scanner) EatRegexp(re *regexp.Regexp, match *Scanner, captures []Scanner) (n int, ok bool)

EatRegexp eats the text matching a regexp, populating match (if != nil) with the whole match and captures (if != nil) with any captured groups. Returns n as the number of captures set and ok iff a match was found.

func (*Scanner) EatString

func (r *Scanner) EatString(s string, eaten *Scanner) bool

func (Scanner) Format

func (r Scanner) Format(state fmt.State, c rune)

func (Scanner) Offset

func (r Scanner) Offset() int

func (Scanner) Skip

func (r Scanner) Skip(i int) *Scanner

func (Scanner) Slice

func (r Scanner) Slice(a, b int) *Scanner

func (Scanner) String

func (r Scanner) String() string

func (Scanner) StripSource added in v0.4.0

func (r Scanner) StripSource() Scanner

type Tag

type Tag string

type Terminal

type Terminal struct {
	// contains filtered or unexported fields
}

func (Terminal) New

func (t Terminal) New(value string, tag Tag) BaseNode

func (*Terminal) NewFromPtr

func (t *Terminal) NewFromPtr(value string, tag Tag) BaseNode

func (*Terminal) String

func (t *Terminal) String() string

func (*Terminal) Tag

func (t *Terminal) Tag() Tag

Jump to

Keyboard shortcuts

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