Documentation ¶
Index ¶
- Constants
- Variables
- func AssertEqualNodes(t *testing.T, v, u Node) bool
- type Associativity
- type Choice
- type CutPoint
- type Cutpointdata
- type Delim
- type Empty
- type ExtRef
- func (t ExtRef) AsTerm() Term
- func (t ExtRef) Parse(scope Scope, input *Scanner, output *TreeElement, stk *call) (out error)
- func (t ExtRef) Parser(name Rule, c cache) Parser
- func (t ExtRef) Resolve(oldRule, newRule Rule) Term
- func (t ExtRef) String() string
- func (t ExtRef) Unparse(g Grammar, te TreeElement, w io.Writer) (n int, err error)
- type ExternalRef
- type ExternalRefs
- type Extra
- type FatalError
- type Grammar
- type LRTGen
- type LookAhead
- type Named
- type Node
- func (n Node) Count() int
- func (n Node) Format(state fmt.State, c rune)
- func (n Node) Get(path ...int) TreeElement
- func (n Node) GetNode(path ...int) Node
- func (n Node) GetScanner(path ...int) Scanner
- func (n Node) GetString(path ...int) string
- func (Node) IsTreeElement()
- func (n Node) Normalize() Node
- func (n Node) String() string
- type Oneof
- type ParseError
- type Parser
- type Parsers
- func (p Parsers) Grammar() Grammar
- func (p Parsers) HasRule(rule Rule) bool
- func (p Parsers) MustParse(rule Rule, input *Scanner) TreeElement
- func (p Parsers) Node() any
- func (p Parsers) Parse(rule Rule, input *Scanner) (TreeElement, error)
- func (p Parsers) ParseWithExternals(rule Rule, input *Scanner, exts ExternalRefs) (TreeElement, error)
- func (p Parsers) Unparse(e TreeElement, w io.Writer) (n int, err error)
- type Quant
- type RE
- type REF
- func (t REF) AsTerm() Term
- func (t *REF) Parse(scope Scope, input *Scanner, output *TreeElement, stk *call) (out error)
- func (t REF) Parser(rule Rule, c cache) Parser
- func (t REF) Resolve(oldRule, newRule Rule) Term
- func (t REF) String() string
- func (t REF) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err error)
- type Rule
- type S
- type Scanner
- func (s Scanner) Contains(sn Scanner) bool
- func (s Scanner) Context(limitLines int) string
- func (s *Scanner) Eat(i int, eaten *Scanner) *Scanner
- func (s *Scanner) EatRegexp(re *regexp.Regexp, match *Scanner, captures []Scanner) (n int, ok bool)
- func (s *Scanner) EatString(str string, eaten *Scanner) bool
- func (s Scanner) Filename() string
- func (s Scanner) Format(state fmt.State, c rune)
- func (s Scanner) IsNil() bool
- func (Scanner) IsTreeElement()
- func (s Scanner) Offset() int
- func (s Scanner) Position() (int, int)
- func (s Scanner) Skip(i int) *Scanner
- func (s Scanner) Slice(a, b int) *Scanner
- func (s Scanner) String() string
- func (s Scanner) StripSource() Scanner
- type Scope
- func (s Scope) GetCutPoint() Cutpointdata
- func (s Scope) GetExternal(ident string) ExternalRef
- func (s Scope) GetVal(ident string) (Parser, TreeElement, bool)
- func (s Scope) Has(ident string) bool
- func (s Scope) Keys() frozen.Set[string]
- func (s Scope) Merge(t Scope) Scope
- func (s Scope) ReplaceCutPoint(force bool) (newScope Scope, prev, replacement Cutpointdata)
- func (s Scope) String() string
- func (s Scope) With(ident string, v any) Scope
- func (s Scope) WithExternals(extRefs ExternalRefs) Scope
- func (s Scope) WithVal(ident string, p Parser, val TreeElement) Scope
- type ScopedGrammar
- type Seq
- type Stack
- type StopError
- type Term
- type TreeElement
- type UnconsumedInputError
Constants ¶
const ( StackDelim = "@" At = Rule(StackDelim) WrapRE = Rule(".wrapRE") )
Variables ¶
var ( NoLimit = -1 DefaultLimit = 1 )
Functions ¶
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 Cutpointdata ¶ added in v0.21.0
type Cutpointdata int32
type Delim ¶ added in v0.10.0
type Delim struct { Term Term Sep Term Assoc Associativity CanStartWithSep bool CanEndWithSep bool }
type Empty ¶ added in v0.10.0
type Empty struct{}
func (Empty) IsTreeElement ¶ added in v0.10.0
func (Empty) IsTreeElement()
type ExtRef ¶ added in v0.13.0
type ExtRef string
type ExternalRef ¶ added in v0.13.0
type ExternalRef func(scope Scope, input *Scanner) (TreeElement, error)
type ExternalRefs ¶ added in v0.13.0
type ExternalRefs map[string]ExternalRef
type FatalError ¶ added in v0.13.0
type FatalError struct { ParseError Cutpointdata }
type Grammar ¶ added in v0.10.0
func (Grammar) Compile ¶ added in v0.10.0
Compile prepares a grammar for parsing. The parser holds a copy of the grammar modified to support parser execution.
type Node ¶
type Node struct { Tag string `json:"tag"` Extra Extra `json:"extra"` Children []TreeElement `json:"nodes"` }
func (Node) Get ¶
func (n Node) Get(path ...int) TreeElement
func (Node) GetScanner ¶
func (Node) IsTreeElement ¶ added in v0.6.0
func (Node) IsTreeElement()
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 Scope, input *Scanner, output *TreeElement, stk *call) error AsTerm() Term }
type Parsers ¶ added in v0.10.0
type Parsers struct {
// contains filtered or unexported fields
}
Parsers holds Parsers generated by Grammar.Compile.
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) Parse ¶ added in v0.10.0
func (p Parsers) Parse(rule Rule, input *Scanner) (TreeElement, error)
func (Parsers) ParseWithExternals ¶ added in v0.13.0
func (p Parsers) ParseWithExternals(rule Rule, input *Scanner, exts ExternalRefs) (TreeElement, error)
Parse parses some source per a given rule.
type Quant ¶ added in v0.10.0
func (Quant) MaxLessThan ¶ added in v0.10.0
type REF ¶ added in v0.10.0
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
func MergeScanners ¶ added in v0.16.0
func NewScanner ¶
func NewScannerAt ¶
func NewScannerWithFilename ¶ added in v0.14.0
func (*Scanner) EatRegexp ¶
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) Filename ¶ added in v0.14.0
The name of the file from which the source is derived (or empty if none).
func (Scanner) IsTreeElement ¶ added in v0.6.0
func (Scanner) IsTreeElement()
func (Scanner) Position ¶ added in v0.14.0
The 1-indexed line and column number of the start of the scanner within the original source.
func (Scanner) StripSource ¶ added in v0.4.0
type Scope ¶ added in v0.13.0
type Scope struct {
// contains filtered or unexported fields
}
func (Scope) GetCutPoint ¶ added in v0.13.0
func (s Scope) GetCutPoint() Cutpointdata
func (Scope) GetExternal ¶ added in v0.13.0
func (s Scope) GetExternal(ident string) ExternalRef
func (Scope) GetVal ¶ added in v0.13.0
func (s Scope) GetVal(ident string) (Parser, TreeElement, bool)
func (Scope) ReplaceCutPoint ¶ added in v0.13.0
func (s Scope) ReplaceCutPoint(force bool) (newScope Scope, prev, replacement Cutpointdata)
func (Scope) WithExternals ¶ added in v0.13.0
func (s Scope) WithExternals(extRefs ExternalRefs) Scope
type ScopedGrammar ¶ added in v0.13.0
func (ScopedGrammar) Parser ¶ added in v0.13.0
func (t ScopedGrammar) Parser(name Rule, c cache) Parser
func (ScopedGrammar) Resolve ¶ added in v0.13.0
func (t ScopedGrammar) Resolve(oldRule, newRule Rule) Term
func (ScopedGrammar) String ¶ added in v0.13.0
func (t ScopedGrammar) String() string
func (ScopedGrammar) Unparse ¶ added in v0.13.0
func (t ScopedGrammar) Unparse(g Grammar, e TreeElement, w io.Writer) (n int, err 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()
}
type UnconsumedInputError ¶ added in v0.13.0
type UnconsumedInputError struct {
// contains filtered or unexported fields
}
func UnconsumedInput ¶ added in v0.13.0
func UnconsumedInput(residue Scanner, result TreeElement) UnconsumedInputError
UnconsumedInput is returned by a successful parse that didn't fully consume the input.
func (UnconsumedInputError) Error ¶ added in v0.13.0
func (e UnconsumedInputError) Error() string
func (UnconsumedInputError) Residue ¶ added in v0.13.0
func (e UnconsumedInputError) Residue() *Scanner
func (UnconsumedInputError) Result ¶ added in v0.13.0
func (e UnconsumedInputError) Result() TreeElement