Documentation
¶
Index ¶
- Variables
- func BoolErrFn[T any](fn func(T) bool) func(T) error
- func BytesSnippet(src []byte, mp MPos, pad int) string
- func FatalError(err error) error
- func FatalError2(tag string, err error) error
- func IsFatalError(err error) bool
- func IterateStructFields(tag string, v any, byPtr bool) iter.Seq2[string, any]
- func ReverseString(s string) string
- func UserDataPtrFn[T any](key string) func(*ParserState) *T
- type MFn
- func AppendFn[T any](dst func(*ParserState) *[]T, fn VFn[T]) MFn
- func AppendLocal[T any](w *[]T, fn VFn[T]) MFn
- func Assign2Fn[T any](dst func(*ParserState) **T, fn VFn[T]) MFn
- func Assign2Local[T any](v **T, fn VFn[T]) MFn
- func AssignFn[T any](dst func(*ParserState) *T, fn VFn[T]) MFn
- func AssignLocal[T any](v *T, fn VFn[T]) MFn
- func Debug2(fn func()) MFn
- type MPos
- type ParserState
- type Pos
- type Rules
- func (g Rules) And(fns ...MFn) MFn
- func (g Rules) AnyExceptNewline() MFn
- func (g Rules) AnyRune() MFn
- func (g Rules) AsciiLetter() MFn
- func (g Rules) Bool() MFn
- func (g Rules) BruteCoverPos(backward, forward MFn) MFn
- func (g Rules) BruteCoverPosEnd(backward, forward MFn) MFn
- func (g Rules) Byte(b byte) MFn
- func (g Rules) ByteFn(fn func(byte) bool) MFn
- func (g Rules) Debug(on bool, prefix string, fn MFn) MFn
- func (g Rules) DebugAnd(on bool, prefix string, fns ...MFn) MFn
- func (g Rules) DebugOr(on bool, prefix string, fns ...MFn) MFn
- func (g Rules) Digit() MFn
- func (g Rules) DigitNotZero() MFn
- func (g Rules) Digits() MFn
- func (g Rules) EmptyLinesExceptNewline(ignore MFn) MFn
- func (g Rules) Eof() MFn
- func (g Rules) EofAbs() MFn
- func (g Rules) Escape(esc rune) MFn
- func (g Rules) Fail() MFn
- func (g Rules) FatalOnError(tag string, fn MFn) MFn
- func (g Rules) Float() MFn
- func (g Rules) Float2(sep rune) MFn
- func (g Rules) HexBytes() MFn
- func (g Rules) Identifier() MFn
- func (g Rules) Integer() MFn
- func (g Rules) IsTrue(v bool) MFn
- func (g Rules) LastAnyRune() MFn
- func (g Rules) Letter() MFn
- func (g Rules) LineComment1(open string) MFn
- func (g Rules) Loop1(fn MFn) MFn
- func (g Rules) LoopConsumeUntil(consumeFn, untilFn MFn) MFn
- func (g Rules) LoopSep(optLastSep bool, fn, sepFn MFn) MFn
- func (g Rules) LoopSepAllowEmpty(fn, sepFn MFn) MFn
- func (g Rules) LoopToNLOrEof(esc rune, includeNL bool) MFn
- func (g Rules) MaxNRunes(n int) MFn
- func (g Rules) NRunes(n int) MFn
- func (g Rules) Newline() MFn
- func (g Rules) NoOp() MFn
- func (g Rules) NoOp2(fn func() error) MFn
- func (g Rules) Not(fn MFn) MFn
- func (g Rules) Optional(fn MFn) MFn
- func (g Rules) Or(fns ...MFn) MFn
- func (g Rules) Parse(ps *ParserState, fn MFn) (Pos, error)
- func (g Rules) ParseAt(ps *ParserState, pos Pos, fn MFn) (Pos, error)
- func (g Rules) Peek(fn MFn) MFn
- func (g Rules) PeekBackN(n int, fn MFn) MFn
- func (g Rules) QuotedSection(quote string, esc rune, consume MFn) MFn
- func (g Rules) QuotedString1() MFn
- func (g Rules) QuotedString2(esc rune, maxLen1, maxLen2 int) MFn
- func (g Rules) ReverseSource(fn MFn) MFn
- func (g Rules) Rune(ru rune) MFn
- func (g Rules) RuneAnyOf(rus ...rune) MFn
- func (g Rules) RuneAnyOfString(s string) MFn
- func (g Rules) RuneFn(fn func(rune) bool) MFn
- func (g Rules) RuneNotAnyOf(rus ...rune) MFn
- func (g Rules) Section(open, close string, esc rune, newlineCloses, eofCloses bool, consume MFn) MFn
- func (g Rules) Seq(s string) MFn
- func (g Rules) SeqOrMid(s string) MFn
- func (g Rules) Sign() MFn
- func (g Rules) Sof() MFn
- func (g Rules) SofAbs() MFn
- func (g Rules) Sop() MFn
- func (g Rules) Space() MFn
- func (g Rules) Spaces() MFn
- func (g Rules) SpacesExceptNewline() MFn
- func (g Rules) ToIndexByte(b byte) MFn
- func (g Rules) ToIndexByteOrEnd(b byte) MFn
- func (g Rules) ToLastIndexByte(b byte) MFn
- func (g Rules) ToLastIndexByteOrStart(b byte) MFn
- func (g Rules) Token(fn MFn) MFn
- func (g Rules) UnicodeLetter() MFn
- func (g Rules) VBool() VFn[bool]
- func (g Rules) VByte() VFn[byte]
- func (g Rules) VBytes(fn MFn) VFn[[]byte]
- func (g Rules) VFloat() VFn[float64]
- func (g Rules) VIdentifier() VFn[string]
- func (g Rules) VInteger() VFn[int]
- func (g Rules) VLastRune() VFn[rune]
- func (g Rules) VQuotedString1() VFn[string]
- func (g Rules) VRune() VFn[rune]
- func (g Rules) VString(fn MFn) VFn[string]
- func (g Rules) VTime(fmt string) VFn[time.Time]
- func (g Rules) WithBounds(back, forward int, fn MFn) MFn
- func (g Rules) WithBoundsAbs(start, end Pos, fn MFn) MFn
- func (g Rules) WithLineBounds(back, forward int, fn MFn) MFn
- type VFn
- func VAny[T any](fn VFn[T]) VFn[any]
- func VAppend[T any](fn VFn[T]) VFn[[]T]
- func VCast[T, U any](fn VFn[U]) VFn[T]
- func VConst[T any](fn MFn, v T) VFn[T]
- func VFromMPos[T any](fn MFn, makeFn func(*ParserState, MPos) T) VFn[T]
- func VOr[T any](fns ...VFn[T]) VFn[T]
- func VToken[T any](fn VFn[T]) VFn[T]
- type VHandler
- type VMaker
Constants ¶
This section is empty.
Variables ¶
var NoMatchErr = fmt.Errorf("no match")
Functions ¶
func FatalError ¶
func FatalError2 ¶
func IsFatalError ¶
IsFatalError is in the parser hot path, so keep it as a shallow check and preserve fatal wrapping at API boundaries.
func IterateStructFields ¶
func ReverseString ¶
func UserDataPtrFn ¶
func UserDataPtrFn[T any](key string) func(*ParserState) *T
Types ¶
type MFn ¶
type MFn func(*ParserState, Pos) (MPos, error)
func AppendLocal ¶
func Assign2Local ¶
func AssignLocal ¶
type MPos ¶
MPos (match position) stores the start position passed to a rule and the end position returned by it; rules may move forward or backward, so End can be lower than Start.
type ParserState ¶
type ParserState struct {
UserData map[string]any
// Ignore is used by Token to skip input before matching; set it before parsing and do not modify it while a parse is running.
Ignore MFn
// contains filtered or unexported fields
}
func NewParserStateFromBytes ¶
func NewParserStateFromBytes(src []byte) *ParserState
func NewParserStateFromString ¶
func NewParserStateFromString(s string) *ParserState
func (*ParserState) Snippet ¶
func (ps *ParserState) Snippet(mp MPos) string
func (*ParserState) Source ¶
func (ps *ParserState) Source(mp MPos) []byte
func (*ParserState) SourceStr ¶
func (ps *ParserState) SourceStr(mp MPos) string
type Rules ¶
type Rules struct{}
Rules is the public API for building and running parser rules. ParserState holds the source, ignore rule, and runtime state for a single parse. Built rules are MFn values and can be reused with different ParserState values. When building parsers, keep construction helpers separate from grammar rules: helpers may read/write parse state, create values from MPos, or wrap a provided rule with an action, but should not hide the grammar shape they receive. Prefer the pattern "helpers first, separator, grammar block after": define helpers such as data(ps), newArg(ps,mp), appendArg(fn), or assignPath(fn), then after //---------- define visible rules such as quotedString, spaces, arg, part, parts, and the final parse rule. Example: appendField(field) belongs above the separator because it only stores a matched value, while field := g.Loop1(g.Or(g.Escape(esc), g.QuotedString2(...), itemRune)) belongs below the separator because it describes the grammar.
func (Rules) AnyExceptNewline ¶
func (Rules) AsciiLetter ¶
func (Rules) BruteCoverPos ¶
BruteCoverPos uses backward func + brute forward attempts until covering pos.
func (Rules) BruteCoverPosEnd ¶
BruteCoverPosEnd is like BruteCoverPos, but also matches when forward ends exactly at pos.