Documentation ¶
Index ¶
- Variables
- func StdShortcuts() map[rune]Matcher
- type Buffer
- func (r *Buffer[V]) Add(data V)
- func (r *Buffer[V]) Clear(initialCapacity int)
- func (r Buffer[V]) Ended() bool
- func (r Buffer[V]) Last() *V
- func (r Buffer[V]) Len() int
- func (r Buffer[V]) Peek() *V
- func (r Buffer[V]) Pos() int
- func (r *Buffer[V]) Read() *V
- func (r *Buffer[V]) RemoveLast() *V
- func (r *Buffer[V]) Reset(i int)
- func (r *Buffer[V]) Set(data []V)
- type Input
- type LogFn
- type Logger
- type MatchAny
- type MatchChars
- type MatchLineEnd
- type MatchLineStart
- type MatchLiteral
- type MatchMaybe
- type MatchOneOf
- type MatchReference
- type MatchRepeat
- type MatchRepeatMaybe
- type MatchRepeatRange
- type MatchResult
- type MatchRule
- type MatchShortcut
- type Matcher
- type MatcherMatch
- type Position
- type Range
- type Rule
- type RuleMatch
- type RulePattern
- type RulePatternParsed
- type RuleSet
- type RuleToken
- type RuleTokenKind
- type Rune
- type RuneBuffer
- func (b *RuneBuffer) Ended() bool
- func (b RuneBuffer) Get(start, end int) string
- func (b RuneBuffer) GetRunes(start, end int) []rune
- func (b RuneBuffer) Len() int
- func (b RuneBuffer) Max() Position
- func (b RuneBuffer) Peek() (r *Rune)
- func (b RuneBuffer) Pos() Position
- func (b *RuneBuffer) Read() (r *Rune)
- func (b *RuneBuffer) Reset(pos Position)
- func (b *RuneBuffer) Set(data string)
- type Set
- type Stack
Constants ¶
This section is empty.
Variables ¶
var ( MatchYes = MatchResult{Matched: true} MatchNo = MatchResult{Matched: false} )
var ErrCharsNoEnd = errors.New("missing ] at end of chars")
var ErrEndOfInput = errors.New("end of input")
var ErrOneOfDelimiter = errors.New("one of delimiter")
var ErrOneOfEnd = errors.New("one of end")
var ErrOneOfNoEnd = errors.New("missing ) at end of one of")
var ErrRangeInvalid = errors.New("range has invalid numbers, min is optional but must be 0 or more and max is optional and must be more than or equal to min")
var ErrRangeNoDelimiter = errors.New("missing , in range")
var ErrRangeNoEnd = errors.New("missing } at end of range")
var ErrReadToEnd = errors.New("read to fail")
var ErrRuleNoEnd = errors.New("missing > at end of rule")
var ErrUnexpectedToken = errors.New("unexpected token")
Functions ¶
func StdShortcuts ¶
Types ¶
type Buffer ¶
type Buffer[V any] struct { // contains filtered or unexported fields }
func (*Buffer[V]) RemoveLast ¶
func (r *Buffer[V]) RemoveLast() *V
type Input ¶
type Input struct { Matchers []MatcherMatch Runes *RuneBuffer // contains filtered or unexported fields }
The parsed output
type Logger ¶
type Logger struct { OnGetGreedyMatches func(input *RuneBuffer, out *RuleMatch, repeater, repeating Matcher, repeatMin, repeatMax, greedyMatches int, start Position) OnSetGreedyMatches func(input *RuneBuffer, out *RuleMatch, repeater, repeating Matcher, repeatMin, repeatMax, greedyMatches int, start Position) OnDecreaseGreedyMatches func(input *RuneBuffer, out *RuleMatch, resetToMatcher Matcher, resetTo int, greediness int) OnMatchError func(input *RuneBuffer, out *RuleMatch, m Matcher, err error) OnMatch func(input *RuneBuffer, out *RuleMatch, m Matcher, start Position) OnNotMatch func(input *RuneBuffer, out *RuleMatch, m Matcher, start Position) }
func NewFuncLogger ¶
func NewStdLogger ¶
func NewStdLogger() Logger
type MatchAny ¶
type MatchAny struct {
// contains filtered or unexported fields
}
type MatchChars ¶
func (MatchChars) ID ¶
func (m MatchChars) ID() int
func (MatchChars) Match ¶
func (m MatchChars) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchChars) String ¶
func (m MatchChars) String() string
type MatchLineEnd ¶
type MatchLineEnd struct {
// contains filtered or unexported fields
}
func (MatchLineEnd) ID ¶
func (m MatchLineEnd) ID() int
func (MatchLineEnd) Match ¶
func (m MatchLineEnd) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchLineEnd) String ¶
func (m MatchLineEnd) String() string
type MatchLineStart ¶
type MatchLineStart struct {
// contains filtered or unexported fields
}
func (MatchLineStart) ID ¶
func (m MatchLineStart) ID() int
func (MatchLineStart) Match ¶
func (m MatchLineStart) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchLineStart) String ¶
func (m MatchLineStart) String() string
type MatchLiteral ¶
type MatchLiteral struct { Literal rune // contains filtered or unexported fields }
func (MatchLiteral) ID ¶
func (m MatchLiteral) ID() int
func (MatchLiteral) Match ¶
func (m MatchLiteral) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchLiteral) String ¶
func (m MatchLiteral) String() string
type MatchMaybe ¶
type MatchMaybe struct { Maybe Matcher // contains filtered or unexported fields }
func (MatchMaybe) ID ¶
func (m MatchMaybe) ID() int
func (MatchMaybe) Match ¶
func (m MatchMaybe) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchMaybe) String ¶
func (m MatchMaybe) String() string
type MatchOneOf ¶
type MatchOneOf struct { OneOf []Buffer[Matcher] Capture int Reset bool Not bool // contains filtered or unexported fields }
func (MatchOneOf) ID ¶
func (m MatchOneOf) ID() int
func (MatchOneOf) Match ¶
func (m MatchOneOf) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchOneOf) String ¶
func (m MatchOneOf) String() string
type MatchReference ¶
type MatchReference struct { Captured int // contains filtered or unexported fields }
func (MatchReference) ID ¶
func (m MatchReference) ID() int
func (MatchReference) Match ¶
func (m MatchReference) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchReference) String ¶
func (m MatchReference) String() string
type MatchRepeat ¶
type MatchRepeat struct { Repeat Matcher // contains filtered or unexported fields }
func (MatchRepeat) ID ¶
func (m MatchRepeat) ID() int
func (MatchRepeat) Match ¶
func (m MatchRepeat) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchRepeat) String ¶
func (m MatchRepeat) String() string
type MatchRepeatMaybe ¶
type MatchRepeatMaybe struct { RepeatMaybe Matcher // contains filtered or unexported fields }
func (MatchRepeatMaybe) ID ¶
func (m MatchRepeatMaybe) ID() int
func (MatchRepeatMaybe) Match ¶
func (m MatchRepeatMaybe) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchRepeatMaybe) String ¶
func (m MatchRepeatMaybe) String() string
type MatchRepeatRange ¶
type MatchRepeatRange struct { RepeatRange Matcher Min int Max int // contains filtered or unexported fields }
func (MatchRepeatRange) ID ¶
func (m MatchRepeatRange) ID() int
func (MatchRepeatRange) Match ¶
func (m MatchRepeatRange) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchRepeatRange) String ¶
func (m MatchRepeatRange) String() string
type MatchResult ¶
type MatchResult struct { Matched bool // A matcher that matched can have this number of alternative states. // For a repeating matcher this represents how many greedy matches over the // minimum it had. For a matcher with multiple options this represents the // number of options it never tried. This can be passed down to the Match // method with a decreased amount to force the matcher to try the alternatives // because the original match was not Alternatives *int // The children of this match result. Children []MatchResult }
func (*MatchResult) ChildAt ¶
func (mr *MatchResult) ChildAt(i int) *MatchResult
func (*MatchResult) SetChild ¶
func (mr *MatchResult) SetChild(i int, child MatchResult)
func (*MatchResult) TakeAlternative ¶
func (mr *MatchResult) TakeAlternative() bool
func (MatchResult) WithAlternatives ¶
func (mr MatchResult) WithAlternatives(alternatives int) MatchResult
type MatchShortcut ¶
type MatchShortcut struct { Shortcut Matcher // contains filtered or unexported fields }
func (MatchShortcut) ID ¶
func (m MatchShortcut) ID() int
func (MatchShortcut) Match ¶
func (m MatchShortcut) Match(rs RuleSet, input *RuneBuffer, out *RuleMatch) (bool, error)
func (MatchShortcut) String ¶
func (m MatchShortcut) String() string
type MatcherMatch ¶
type MatcherMatch struct { // The matcher that matched Matcher Matcher // The index of this node in its matchers repitition logic. This is stored here // for when the matching logic needs to backtrack on its greediness to find a match. GreedyMatches int // The RuleMatch this matcher belongs to RuleMatch *RuleMatch }
A matcher matched over
type Range ¶
func (Range) Get ¶
func (c Range) Get(in RuneBuffer) string
func (Range) GetRunes ¶
func (c Range) GetRunes(in RuneBuffer) []rune
type RuleMatch ¶
type RuleMatch struct { // The range over what this matched. Range // The alias/rule that created this node. Name string // The rule that was matched Rule *Rule // The matchers that matched in this rule Matchers []MatcherMatch // The captured groups in this rule Captures map[int][]Range // The parent of this node. Parent *RuleMatch // The children of this node as they occurred in the input. Children []*RuleMatch // The name-to-output nodes ChildIndex map[string][]int // Global input dat Input *Input }
A rule matched over some range of input
type RulePattern ¶
type RulePattern string
func (RulePattern) Parse ¶
func (r RulePattern) Parse() (parsed RulePatternParsed, err error)
type RulePatternParsed ¶
type RuleSet ¶
type RuleSet struct { Shortcuts map[rune]Matcher Logger Logger // contains filtered or unexported fields }
func NewRuleSet ¶
func NewStdRuleSet ¶
func NewStdRuleSet(rules map[string]RulePattern) (RuleSet, error)
type RuleToken ¶
type RuleToken struct { Kind RuleTokenKind Rune }
type RuleTokenKind ¶
type RuleTokenKind rune
## Language rules rules - `[]` = characters within are valid for matching, if a hyphen is between two characters in a sequence its a range - `.` = any character - `\` = escapes [](){}*+?.^$! - `\shortcut` = is a matcher in a shortcut map in the rule set - `^` = start of line - `$` = end of line - `*` = 0 or more of previous matcher - `+` = 1 or more of previous matcher - `?` = 0 or 1 of previous matcher - `{n}` = n of previous matcher - `{min,max}` = min to max of previous matcher. min defaults to 0, max defaults to inf. - `(a|b|c)` = one of the options - `(?=a)` = matches if a matches and doesn't read it - `(?!a)` = matches if a does not match and doesn't read it - `(?:a)` = matches if a matches but doesn't capture it - `\n` = matches group "n" captured in rule - `<refName:ruleName>` = a rule has a subset rule that's named. if the name is reused in a rule it is a list of values - `<ruleName>` = a rule has a subset rule that's named the ruleName - any other characters are considered a literal
var ( RuleTokenEOF RuleTokenKind = 0 RuleTokenEscape RuleTokenKind = '\\' RuleTokenAny RuleTokenKind = '.' RuleTokenRepeatMaybe RuleTokenKind = '*' RuleTokenRepeat RuleTokenKind = '+' RuleTokenRepeatRangeStart RuleTokenKind = '{' RuleTokenRepeatRangeEnd RuleTokenKind = '}' RuleTokenRepeatRangeDelimiter RuleTokenKind = ',' RuleTokenMaybe RuleTokenKind = '?' RuleTokenLiteral RuleTokenKind = 'l' RuleTokenShortcut RuleTokenKind = 's' RuleTokenOneOfStart RuleTokenKind = '(' RuleTokenOneOfEnd RuleTokenKind = ')' RuleTokenOneOfDelimiter RuleTokenKind = '|' RuleTokenCharsStart RuleTokenKind = '[' RuleTokenCharsEnd RuleTokenKind = ']' RuleTokenCharsRange RuleTokenKind = '-' RuleTokenCharsNot RuleTokenKind = '^' RuleTokenRuleStart RuleTokenKind = '<' RuleTokenRuleEnd RuleTokenKind = '>' RuleTokenRuleDelimiter RuleTokenKind = ':' RuleTokenLineStart RuleTokenKind = '^' RuleTokenLineEnd RuleTokenKind = '$' )
func RuneToRuleTokenKind ¶
func RuneToRuleTokenKind(k rune) RuleTokenKind
type RuneBuffer ¶
type RuneBuffer struct {
// contains filtered or unexported fields
}
func NewRuneBuffer ¶
func NewRuneBuffer(data string) *RuneBuffer
func (*RuneBuffer) Ended ¶
func (b *RuneBuffer) Ended() bool
func (RuneBuffer) Get ¶
func (b RuneBuffer) Get(start, end int) string
func (RuneBuffer) GetRunes ¶
func (b RuneBuffer) GetRunes(start, end int) []rune
func (RuneBuffer) Len ¶
func (b RuneBuffer) Len() int
func (RuneBuffer) Max ¶
func (b RuneBuffer) Max() Position
func (RuneBuffer) Peek ¶
func (b RuneBuffer) Peek() (r *Rune)
func (RuneBuffer) Pos ¶
func (b RuneBuffer) Pos() Position
func (*RuneBuffer) Read ¶
func (b *RuneBuffer) Read() (r *Rune)
func (*RuneBuffer) Reset ¶
func (b *RuneBuffer) Reset(pos Position)
func (*RuneBuffer) Set ¶
func (b *RuneBuffer) Set(data string)
type Set ¶
type Set[V comparable] map[V]struct{}
func NewSet ¶
func NewSet[V comparable](values ...V) Set[V]