pscan

package
v1.3.10 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EOF = io.EOF
View Source
var NoMatchErr = errors.New("no match")
View Source
var SOF = errors.New("SOF") // start-of-file (as opposed to EOF)

Functions

func ContainsRune

func ContainsRune(rs []rune, ru rune) bool

func SurroundingString

func SurroundingString(b []byte, k int, pad int) string

Types

type Error

type Error struct {
	Fatal bool
	// contains filtered or unexported fields
}

func (Error) Error

func (e Error) Error() string

type MFn

type MFn func(pos int) (int, error) // match func

type Match

type Match struct {
	W *Wrap
	// contains filtered or unexported fields
}

func (*Match) And

func (m *Match) And(pos int, fns ...MFn) (int, error)

runs in order, even when in reverse mode

func (*Match) AndR

func (m *Match) AndR(pos int, fns ...MFn) (int, error)

"and" reversible: in reverse mode, runs the last fn first

func (*Match) Byte

func (m *Match) Byte(pos int, b byte) (int, error)

func (*Match) ByteFn

func (m *Match) ByteFn(pos int, fn func(byte) bool) (int, error)

func (*Match) ByteFnLoop

func (m *Match) ByteFnLoop(pos int, fn func(byte) bool) (int, error)

one or more

func (*Match) ByteSequence

func (m *Match) ByteSequence(pos int, seq []byte) (int, error)

func (*Match) BytesValue

func (m *Match) BytesValue(pos int, fn MFn) (any, int, error)

func (*Match) Digit

func (m *Match) Digit(pos int) (int, error)

func (*Match) Digits

func (m *Match) Digits(pos int) (int, error)

func (*Match) DoubleQuotedString

func (m *Match) DoubleQuotedString(pos int, maxLen int) (int, error)

func (*Match) Eof

func (m *Match) Eof(pos int) (int, error)

func (*Match) EscapeAny

func (m *Match) EscapeAny(pos int, escape rune) (int, error)

func (*Match) FatalOnError

func (m *Match) FatalOnError(pos int, s string, fn MFn) (int, error)

func (*Match) Float

func (m *Match) Float(pos int) (int, error)

func (*Match) Float64Value

func (m *Match) Float64Value(pos int) (any, int, error)

func (*Match) FnTrue

func (m *Match) FnTrue(pos int, fn func() bool) (int, error)

func (*Match) Int64Value

func (m *Match) Int64Value(pos int) (any, int, error)

func (*Match) IntFnValue

func (m *Match) IntFnValue(pos int, fn MFn) (any, int, error)

func (*Match) IntValue

func (m *Match) IntValue(pos int) (any, int, error)

func (*Match) Integer

func (m *Match) Integer(pos int) (int, error)

func (*Match) Letter

func (m *Match) Letter(pos int) (int, error)

func (*Match) LimitedLoop

func (m *Match) LimitedLoop(pos int, min, max int, fn MFn) (int, error)

max<=-1 means no upper limit

func (*Match) Loop

func (m *Match) Loop(pos int, fn MFn) (int, error)

one or more

func (*Match) LoopSep

func (m *Match) LoopSep(pos int, fn, sep MFn) (int, error)

func (*Match) LoopSepCanHaveLast

func (m *Match) LoopSepCanHaveLast(pos int, fn, sep MFn) (int, error)

func (*Match) MustErr

func (m *Match) MustErr(pos int, fn MFn) (int, error)

func (*Match) NBytes

func (m *Match) NBytes(pos int, n int) (int, error)

func (*Match) NBytesFn

func (m *Match) NBytesFn(pos int, n int, fn func(byte) bool) (int, error)

func (*Match) NLoop

func (m *Match) NLoop(pos int, n int, fn MFn) (int, error)

must have n

func (*Match) NRunes

func (m *Match) NRunes(pos int, n int) (int, error)

func (*Match) NRunesFn

func (m *Match) NRunesFn(pos int, n int, fn func(rune) bool) (int, error)

func (*Match) NotEof

func (m *Match) NotEof(p int) (int, error)

func (*Match) OnValue

func (m *Match) OnValue(pos int, fn VFn, cb func(any)) (int, error)

func (*Match) OnValue2

func (m *Match) OnValue2(pos int, fn VFn, cb func(any) error) (int, error)

func (*Match) OneByte

func (m *Match) OneByte(pos int) (int, error)

func (*Match) OneRune

func (m *Match) OneRune(pos int) (int, error)

equivalent to NRunes(1) but faster

func (*Match) OptLoop

func (m *Match) OptLoop(pos int, fn MFn) (int, error)

optional loop: zero or more

func (*Match) Optional

func (m *Match) Optional(pos int, fn MFn) (int, error)

func (*Match) Or

func (m *Match) Or(pos int, fns ...MFn) (int, error)

runs in order, even when in reverse mode

func (*Match) OrValue

func (m *Match) OrValue(pos int, fns ...VFn) (any, int, error)

func (*Match) PrintfErr

func (m *Match) PrintfErr(pos int, f string, args ...any) (int, error)

useful in Or's

func (*Match) PrintfNoErr

func (m *Match) PrintfNoErr(pos int, f string, args ...any) (int, error)

useful in And's

func (*Match) PtrFalse

func (m *Match) PtrFalse(pos int, v *bool) (int, error)

func (*Match) PtrFn

func (m *Match) PtrFn(pos int, fn *MFn) (int, error)

func (*Match) PtrTrue

func (m *Match) PtrTrue(pos int, v *bool) (int, error)

func (*Match) QuotedString

func (m *Match) QuotedString(pos int) (int, error)

func (*Match) QuotedString2

func (m *Match) QuotedString2(pos int, esc rune, maxLen1, maxLen2 int) (int, error)

allows escaped runes with esc!=0

func (*Match) RegexpFromStart

func (m *Match) RegexpFromStart(pos int, res string, cache bool, maxLen int) (int, error)

func (*Match) RegexpFromStartCached

func (m *Match) RegexpFromStartCached(pos int, res string, maxLen int) (int, error)

func (*Match) ReverseMode

func (m *Match) ReverseMode(pos int, reverse bool, fn MFn) (int, error)

func (*Match) Rune

func (m *Match) Rune(pos int, ru rune) (int, error)

func (*Match) RuneFn

func (m *Match) RuneFn(pos int, fn func(rune) bool) (int, error)

func (*Match) RuneFnLoop

func (m *Match) RuneFnLoop(pos int, fn func(rune) bool) (int, error)

one or more

func (*Match) RuneNoneOf

func (m *Match) RuneNoneOf(pos int, rs []rune) (int, error)

previously "RuneAnyNot"

func (*Match) RuneOneOf

func (m *Match) RuneOneOf(pos int, rs []rune) (int, error)

previously "RuneAny"

func (*Match) RuneRanges

func (m *Match) RuneRanges(pos int, rrs ...RuneRange) (int, error)

func (*Match) RuneSequence

func (m *Match) RuneSequence(pos int, seq []rune) (int, error)

func (*Match) RuneSequenceMid

func (m *Match) RuneSequenceMid(pos int, rs []rune) (int, error)

func (*Match) RuneValue

func (m *Match) RuneValue(pos int, fn MFn) (any, int, error)

func (*Match) Section

func (m *Match) Section(pos int, open, close string, esc rune, failOnNewline bool, maxLen int, eofClose bool, consumeFn MFn) (int, error)

match opened/closed sections.

func (*Match) Sequence

func (m *Match) Sequence(pos int, seq string) (int, error)

func (*Match) SequenceMid

func (m *Match) SequenceMid(pos int, seq string) (int, error)

func (*Match) Spaces

func (m *Match) Spaces(pos int, includeNL bool, escape rune) (int, error)

func (*Match) StaticFalse

func (m *Match) StaticFalse(pos int, v bool) (int, error)

func (*Match) StaticTrue

func (m *Match) StaticTrue(pos int, v bool) (int, error)

func (*Match) StringSection

func (m *Match) StringSection(pos int, openclose string, esc rune, failOnNewline bool, maxLen int, eofClose bool) (int, error)

func (*Match) StringValue

func (m *Match) StringValue(pos int, fn MFn) (any, int, error)

func (*Match) ToNLOrErr

func (m *Match) ToNLOrErr(pos int, includeNL bool, esc rune) (int, error)

type RuneRange

type RuneRange [2]rune // assume [0]<[1]

func (RuneRange) HasRune

func (rr RuneRange) HasRune(ru rune) bool

func (RuneRange) IntersectsRange

func (rr RuneRange) IntersectsRange(rr2 RuneRange) bool

func (RuneRange) String

func (rr RuneRange) String() string

type Scanner

type Scanner struct {
	Reverse bool
	M       *Match
	W       *Wrap
	// contains filtered or unexported fields
}

NOTE: to debug, use fatal error wrappers

func NewScanner

func NewScanner() *Scanner

func (*Scanner) EnsureFatalError

func (sc *Scanner) EnsureFatalError(err error) error

func (*Scanner) NewValueKeeper

func (sc *Scanner) NewValueKeeper() *ValueKeeper

func (*Scanner) NewValueKeepers

func (sc *Scanner) NewValueKeepers(n int) []*ValueKeeper

func (*Scanner) ReadByte

func (sc *Scanner) ReadByte(pos int) (byte, int, error)

func (*Scanner) ReadRune

func (sc *Scanner) ReadRune(pos int) (rune, int, error)

func (*Scanner) SetSrc

func (sc *Scanner) SetSrc(src []byte)

func (*Scanner) SetSrc2

func (sc *Scanner) SetSrc2(src []byte, offset int)

func (*Scanner) SrcByte

func (sc *Scanner) SrcByte(i int) byte

func (*Scanner) SrcError

func (sc *Scanner) SrcError(pos int, err error) error

func (*Scanner) SrcFrom

func (sc *Scanner) SrcFrom(a int) []byte

func (*Scanner) SrcFromTo

func (sc *Scanner) SrcFromTo(a, b int) []byte

func (*Scanner) SrcFullFromOffset

func (sc *Scanner) SrcFullFromOffset() []byte

WARNING: use with caution, using pos in resulting []byte might fail when there is offset

func (*Scanner) SrcLen

func (sc *Scanner) SrcLen() int

func (*Scanner) SrcMin

func (sc *Scanner) SrcMin() int

func (*Scanner) SrcSection

func (sc *Scanner) SrcSection(pos int) string

func (*Scanner) SrcTo

func (sc *Scanner) SrcTo(b int) []byte

func (*Scanner) ValidPos

func (sc *Scanner) ValidPos(i int) int

type VFn

type VFn func(pos int) (any, int, error) // value func

type ValueKeeper

type ValueKeeper struct {
	V any // value
	// contains filtered or unexported fields
}

func (*ValueKeeper) KeepValue

func (vk *ValueKeeper) KeepValue(pos int, fn VFn) (int, error)

func (*ValueKeeper) WKeepValue

func (vk *ValueKeeper) WKeepValue(fn VFn) MFn

type Wrap

type Wrap struct {
	M *Match
	// contains filtered or unexported fields
}

func (*Wrap) And

func (w *Wrap) And(fns ...MFn) MFn

func (*Wrap) AndR

func (w *Wrap) AndR(fns ...MFn) MFn

func (*Wrap) Byte

func (w *Wrap) Byte(b byte) MFn

func (*Wrap) ByteFn

func (w *Wrap) ByteFn(fn func(byte) bool) MFn

func (*Wrap) ByteFnLoop

func (w *Wrap) ByteFnLoop(fn func(byte) bool) MFn

func (*Wrap) ByteSequence

func (w *Wrap) ByteSequence(seq []byte) MFn

func (*Wrap) BytesValue

func (w *Wrap) BytesValue(fn MFn) VFn

func (*Wrap) Digit

func (w *Wrap) Digit() MFn

func (*Wrap) Digits

func (w *Wrap) Digits() MFn

func (*Wrap) DoubleQuotedString

func (w *Wrap) DoubleQuotedString(maxLen int) MFn

func (*Wrap) Eof

func (w *Wrap) Eof() MFn

func (*Wrap) EscapeAny

func (w *Wrap) EscapeAny(escape rune) MFn

func (*Wrap) FatalOnError

func (w *Wrap) FatalOnError(s string, fn MFn) MFn

func (*Wrap) Float

func (w *Wrap) Float() MFn

func (*Wrap) Float64Value

func (w *Wrap) Float64Value() VFn

func (*Wrap) FnTrue

func (w *Wrap) FnTrue(fn func() bool) MFn

func (*Wrap) Int64Value

func (w *Wrap) Int64Value() VFn

func (*Wrap) IntFnValue

func (w *Wrap) IntFnValue(fn MFn) VFn

func (*Wrap) IntValue

func (w *Wrap) IntValue() VFn

func (*Wrap) Integer

func (w *Wrap) Integer() MFn

func (*Wrap) Letter

func (w *Wrap) Letter() MFn

func (*Wrap) LimitedLoop

func (w *Wrap) LimitedLoop(min, max int, fn MFn) MFn

func (*Wrap) Loop

func (w *Wrap) Loop(fn MFn) MFn

func (*Wrap) LoopSep

func (w *Wrap) LoopSep(fn, sep MFn) MFn

func (*Wrap) LoopSepCanHaveLast

func (w *Wrap) LoopSepCanHaveLast(fn, sep MFn) MFn

func (*Wrap) MustErr

func (w *Wrap) MustErr(fn MFn) MFn

func (*Wrap) NBytes

func (w *Wrap) NBytes(n int) MFn

func (*Wrap) NBytesFn

func (w *Wrap) NBytesFn(n int, fn func(byte) bool) MFn

func (*Wrap) NLoop

func (w *Wrap) NLoop(n int, fn MFn) MFn

func (*Wrap) NRunes

func (w *Wrap) NRunes(n int) MFn

func (*Wrap) NRunesFn

func (w *Wrap) NRunesFn(n int, fn func(rune) bool) MFn

func (*Wrap) NotEof

func (w *Wrap) NotEof() MFn

func (*Wrap) OnValue

func (w *Wrap) OnValue(fn VFn, cb func(any)) MFn

func (*Wrap) OnValue2

func (w *Wrap) OnValue2(fn VFn, cb func(any) error) MFn

func (*Wrap) OneByte

func (w *Wrap) OneByte() MFn

func (*Wrap) OneRune

func (w *Wrap) OneRune() MFn

func (*Wrap) OptLoop

func (w *Wrap) OptLoop(fn MFn) MFn

func (*Wrap) Optional

func (w *Wrap) Optional(fn MFn) MFn

func (*Wrap) Or

func (w *Wrap) Or(fns ...MFn) MFn

func (*Wrap) OrValue

func (w *Wrap) OrValue(fns ...VFn) VFn

func (*Wrap) PrintfErr

func (w *Wrap) PrintfErr(f string, args ...any) MFn

func (*Wrap) PrintfNoErr

func (w *Wrap) PrintfNoErr(f string, args ...any) MFn

func (*Wrap) PtrFalse

func (w *Wrap) PtrFalse(v *bool) MFn

func (*Wrap) PtrFn

func (w *Wrap) PtrFn(fn *MFn) MFn

func (*Wrap) PtrTrue

func (w *Wrap) PtrTrue(v *bool) MFn

func (*Wrap) QuotedString

func (w *Wrap) QuotedString() MFn

func (*Wrap) QuotedString2

func (w *Wrap) QuotedString2(esc rune, maxLen1, maxLen2 int) MFn

func (*Wrap) RegexpFromStart

func (w *Wrap) RegexpFromStart(res string, cache bool, maxLen int) MFn

func (*Wrap) RegexpFromStartCached

func (w *Wrap) RegexpFromStartCached(res string, maxLen int) MFn

func (*Wrap) ReverseMode

func (w *Wrap) ReverseMode(reverse bool, fn MFn) MFn

func (*Wrap) Rune

func (w *Wrap) Rune(ru rune) MFn

func (*Wrap) RuneFn

func (w *Wrap) RuneFn(fn func(rune) bool) MFn

func (*Wrap) RuneFnLoop

func (w *Wrap) RuneFnLoop(fn func(rune) bool) MFn

func (*Wrap) RuneNoneOf

func (w *Wrap) RuneNoneOf(rs []rune) MFn

func (*Wrap) RuneOneOf

func (w *Wrap) RuneOneOf(rs []rune) MFn

func (*Wrap) RuneRanges

func (w *Wrap) RuneRanges(rrs ...RuneRange) MFn

func (*Wrap) RuneSequence

func (w *Wrap) RuneSequence(seq []rune) MFn

func (*Wrap) RuneSequenceMid

func (w *Wrap) RuneSequenceMid(rs []rune) MFn

func (*Wrap) RuneValue

func (w *Wrap) RuneValue(fn MFn) VFn

func (*Wrap) Section

func (w *Wrap) Section(open, close string, esc rune, failOnNewline bool, maxLen int, eofClose bool, consumeFn MFn) MFn

func (*Wrap) Sequence

func (w *Wrap) Sequence(seq string) MFn

func (*Wrap) SequenceMid

func (w *Wrap) SequenceMid(seq string) MFn

func (*Wrap) Spaces

func (w *Wrap) Spaces(includeNL bool, escape rune) MFn

func (*Wrap) StaticFalse

func (w *Wrap) StaticFalse(v bool) MFn

func (*Wrap) StaticTrue

func (w *Wrap) StaticTrue(v bool) MFn

func (*Wrap) StringSection

func (w *Wrap) StringSection(openclose string, esc rune, failOnNewline bool, maxLen int, eofClose bool) MFn

func (*Wrap) StringValue

func (w *Wrap) StringValue(fn MFn) VFn

func (*Wrap) ToNLOrErr

func (w *Wrap) ToNLOrErr(includeNL bool, esc rune) MFn

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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