parser

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: Apache-2.0 Imports: 13 Imported by: 7

Documentation

Index

Constants

View Source
const (
	StackDelim = "@"
	At         = Rule(StackDelim)

	WrapRE = Rule(".wrapRE")
)

Variables

This section is empty.

Functions

func AssertEqualNodes

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

func NewScopeWith added in v0.10.0

func NewScopeWith(s frozen.Map, ident string, p Parser, val TreeElement) frozen.Map

Types

type Associativity added in v0.10.0

type Associativity int
const (
	RightToLeft Associativity = iota - 1
	NonAssociative
	LeftToRight
)

func NewAssociativity added in v0.10.0

func NewAssociativity(s string) Associativity

func (Associativity) IsExtra added in v0.10.0

func (Associativity) IsExtra()

func (Associativity) String added in v0.10.0

func (a Associativity) String() string

type Choice added in v0.10.0

type Choice int

func (Choice) IsExtra added in v0.10.0

func (Choice) IsExtra()

type Delim added in v0.10.0

type Delim struct {
	Term            Term
	Sep             Term
	Assoc           Associativity
	CanStartWithSep bool
	CanEndWithSep   bool
}

func L2R added in v0.10.0

func L2R(term, sep Term) Delim

func NonAssoc added in v0.10.0

func NonAssoc(term, sep Term) Delim

func R2L added in v0.10.0

func R2L(term, sep Term) Delim

func (Delim) LRTerms added in v0.10.0

func (t Delim) LRTerms(node Node) lrtgen

func (Delim) Parser added in v0.10.0

func (t Delim) Parser(rule Rule, c cache) Parser

func (Delim) Resolve added in v0.10.0

func (t Delim) Resolve(oldRule, newRule Rule) Term

func (Delim) String added in v0.10.0

func (t Delim) String() string

func (Delim) Unparse added in v0.10.0

func (t Delim) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

type Empty added in v0.10.0

type Empty struct{}

func (Empty) IsTreeElement added in v0.10.0

func (Empty) IsTreeElement()

type Extra added in v0.6.0

type Extra interface {
	IsExtra()
}

type Func

type Func func(scope frozen.Map, input *Scanner, output *TreeElement) error

func (Func) Parse

func (f Func) Parse(scope frozen.Map, input *Scanner, output *TreeElement) error

type Grammar added in v0.10.0

type Grammar map[Rule]Term

func (Grammar) Compile added in v0.10.0

func (g Grammar) Compile(node interface{}) Parsers

Compile prepares a grammar for parsing. The parser holds a copy of the grammar modified to support parser execution.

func (Grammar) String added in v0.10.0

func (g Grammar) String() string

func (Grammar) Unparse added in v0.10.0

func (g Grammar) Unparse(e TreeElement, w io.Writer) (n int, err error)

Unparse inverts the action of a parser, taking a generated AST and producing the source it came from. Currently, it doesn't quite do that, and is only being used for quick eyeballing to validate output.

type Named added in v0.10.0

type Named struct {
	Name string
	Term Term
}

func Eq added in v0.10.0

func Eq(name string, term Term) Named

func (Named) Parser added in v0.10.0

func (t Named) Parser(rule Rule, c cache) Parser

func (Named) Resolve added in v0.10.0

func (t Named) Resolve(oldRule, newRule Rule) Term

func (Named) String added in v0.10.0

func (t Named) String() string

func (Named) Unparse added in v0.10.0

func (t Named) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

type Node

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

func NewNode

func NewNode(tag string, extra Extra, children ...TreeElement) *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) TreeElement

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) IsTreeElement added in v0.6.0

func (Node) IsTreeElement()

func (Node) Normalize added in v0.6.0

func (n Node) Normalize() Node

func (Node) String

func (n Node) String() string

type Oneof added in v0.10.0

type Oneof []Term

func (Oneof) Parser added in v0.10.0

func (t Oneof) Parser(rule Rule, c cache) Parser

func (Oneof) Resolve added in v0.10.0

func (t Oneof) Resolve(oldRule, newRule Rule) Term

func (Oneof) String added in v0.10.0

func (t Oneof) String() string

func (Oneof) Unparse added in v0.10.0

func (t Oneof) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

type ParseError added in v0.10.0

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

func (ParseError) Error added in v0.10.0

func (p ParseError) Error() string

type Parser

type Parser interface {
	Parse(scope frozen.Map, input *Scanner, output *TreeElement) error
}

func Transform

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

type Parsers added in v0.10.0

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

Parsers holds Parsers generated by Grammar.Compile.

func (Parsers) Grammar added in v0.10.0

func (p Parsers) Grammar() Grammar

func (Parsers) HasRule added in v0.12.2

func (p Parsers) HasRule(rule Rule) bool

func (Parsers) MustParse added in v0.10.0

func (p Parsers) MustParse(rule Rule, input *Scanner) TreeElement

MustParse calls Parse and returns the result or panics if an error was returned.

func (Parsers) Node added in v0.10.0

func (p Parsers) Node() interface{}

func (Parsers) Parse added in v0.10.0

func (p Parsers) Parse(rule Rule, input *Scanner) (TreeElement, error)

Parse parses some source per a given rule.

func (Parsers) Unparse added in v0.10.0

func (p Parsers) Unparse(e TreeElement, w io.Writer) (n int, err error)

type Quant added in v0.10.0

type Quant struct {
	Term Term
	Min  int
	Max  int // 0 = infinity
}

func Any added in v0.10.0

func Any(term Term) Quant

func Opt added in v0.10.0

func Opt(term Term) Quant

func Some added in v0.10.0

func Some(term Term) Quant

func (Quant) Contains added in v0.10.0

func (t Quant) Contains(i int) bool

func (Quant) MaxLessThan added in v0.10.0

func (t Quant) MaxLessThan(i int) bool

func (Quant) Parser added in v0.10.0

func (t Quant) Parser(rule Rule, c cache) Parser

func (Quant) Resolve added in v0.10.0

func (t Quant) Resolve(oldRule, newRule Rule) Term

func (Quant) String added in v0.10.0

func (t Quant) String() string

func (Quant) Unparse added in v0.10.0

func (t Quant) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

type RE added in v0.10.0

type RE string

func (RE) Parser added in v0.10.0

func (t RE) Parser(rule Rule, c cache) Parser

func (RE) Resolve added in v0.10.0

func (t RE) Resolve(oldRule, newRule Rule) Term

func (RE) String added in v0.10.0

func (t RE) String() string

func (RE) Unparse added in v0.10.0

func (t RE) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

type REF added in v0.10.0

type REF struct {
	Ident   string
	Default Term
}

func (*REF) Parse added in v0.10.0

func (t *REF) Parse(scope frozen.Map, input *Scanner, output *TreeElement) (out error)

func (REF) Parser added in v0.10.0

func (t REF) Parser(rule Rule, c cache) Parser

func (REF) Resolve added in v0.10.0

func (t REF) Resolve(oldRule, newRule Rule) Term

func (REF) String added in v0.10.0

func (t REF) String() string

func (REF) Unparse added in v0.10.0

func (t REF) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

type Rule added in v0.10.0

type Rule string

func NodeRule added in v0.10.0

func NodeRule(e Node) Rule

func (Rule) Parser added in v0.10.0

func (t Rule) Parser(rule Rule, c cache) Parser

func (Rule) Resolve added in v0.10.0

func (t Rule) Resolve(oldRule, newRule Rule) Term

func (Rule) String added in v0.10.0

func (t Rule) String() string

func (Rule) Unparse added in v0.10.0

func (t Rule) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

type S added in v0.10.0

type S string

func (S) Parser added in v0.10.0

func (t S) Parser(rule Rule, c cache) Parser

func (S) Resolve added in v0.10.0

func (t S) Resolve(oldRule, newRule Rule) Term

func (S) String added in v0.10.0

func (t S) String() string

func (S) Unparse added in v0.10.0

func (t S) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

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) IsTreeElement added in v0.6.0

func (Scanner) IsTreeElement()

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 Seq added in v0.10.0

type Seq []Term

func (Seq) Parser added in v0.10.0

func (t Seq) Parser(rule Rule, c cache) Parser

func (Seq) Resolve added in v0.10.0

func (t Seq) Resolve(oldRule, newRule Rule) Term

func (Seq) String added in v0.10.0

func (t Seq) String() string

func (Seq) Unparse added in v0.10.0

func (t Seq) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)

type Stack added in v0.10.0

type Stack []Term

func (Stack) Parser added in v0.10.0

func (t Stack) Parser(_ Rule, _ cache) Parser

func (Stack) Resolve added in v0.10.0

func (t Stack) Resolve(oldRule, newRule Rule) Term

func (Stack) String added in v0.10.0

func (t Stack) String() string

func (Stack) Unparse added in v0.10.0

func (t Stack) Unparse(_ Grammar, _ TreeElement, _ io.Writer) (int, error)

type Term added in v0.10.0

type Term interface {
	fmt.Stringer
	Parser(name Rule, c cache) Parser
	Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)
	Resolve(oldRule, newRule Rule) Term
}

Term represents the terms of a grammar specification.

type TreeElement added in v0.6.0

type TreeElement interface {
	IsTreeElement()
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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