parseutil

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExtraRunes = "_-~.%@&?!=#+:^" + "(){}[]<>" + "\\/" + " "
View Source
var ParseVolume bool = runtime.GOOS == "windows"
View Source
var PathExtraRunes = RunesExcept(ExtraRunes, excludeResourceRunes+

	":") // line/column
View Source
var PathSeparator rune = rune(os.PathSeparator)
View Source
var ResourceExtraRunes = RunesExcept(ExtraRunes, excludeResourceRunes)

Functions

func AbsFilenameToUrl

func AbsFilenameToUrl(filename string) (string, error)

func AddEscapes

func AddEscapes(str string, escape rune, escapeRunes string) string

func CleanMultiplePathSeps

func CleanMultiplePathSeps(str string, sep rune) string

func CtxErrorStr added in v1.3.3

func CtxErrorStr(rd iorw.ReaderAt, filename string, pos int, msg string, contextSize int) string

func CtxString added in v1.3.3

func CtxString(rd iorw.ReaderAt, pos int, contextSize int) (string, error)

func DetectEnvVar

func DetectEnvVar(str, name string) bool

func EscapeFilename

func EscapeFilename(str string) string

func ExpandIndexEscape

func ExpandIndexEscape(r iorw.ReaderAt, i int, truth bool, fn func(rune) bool, escape rune) int

func ExpandIndexesEscape

func ExpandIndexesEscape(rd iorw.ReaderAt, index int, truth bool, fn func(rune) bool, escape rune) (int, int)

func ExpandLastIndexEscape

func ExpandLastIndexEscape(r iorw.ReaderAt, i int, truth bool, fn func(rune) bool, escape rune) int

func ImproveExpandIndexEscape

func ImproveExpandIndexEscape(r iorw.ReaderAt, i int, escape rune) int

func IndexLineColumn

func IndexLineColumn(rd iorw.ReaderAt, index int) (int, int, error)

Returned line/col values are one-based.

func LineColumnIndex

func LineColumnIndex(rd iorw.ReaderAt, line, column int) (int, error)

Line/col args are one-based.

func ParseFields added in v1.3.1

func ParseFields(s string, fieldSep rune) ([]string, error)

func RemoveEscapes

func RemoveEscapes(str string, escape rune) string

func RemoveEscapesEscapable

func RemoveEscapesEscapable(str string, escape rune, escapable string) string

removes the escape only if escapable

func RemoveFilenameEscapes

func RemoveFilenameEscapes(f string, escape, pathSep rune) string

func RunesExcept

func RunesExcept(runes, except string) string

func TrimLineSpaces

func TrimLineSpaces(str string) string

Useful to compare src code lines.

func TrimLineSpaces2 added in v1.3.1

func TrimLineSpaces2(str string, pre string) string

func UrlToAbsFilename

func UrlToAbsFilename(url2 string) (string, error)

func VersionLessThan added in v1.3.1

func VersionLessThan(a, b string) bool

func VersionOrdinal added in v1.3.1

func VersionOrdinal(version string) string

constructs a byte array (returned as a string) with the count of sequential digits to be able to compare "1.9"<"1.10"

Types

type ByteFunc added in v1.3.3

type ByteFunc func(byte) bool

type FilePos

type FilePos struct {
	Filename     string
	Offset, Len  int // length after offset for a range
	Line, Column int // bigger than zero to be considered
}

func NewFilePosFromResource

func NewFilePosFromResource(res *Resource) *FilePos

func ParseFilePos

func ParseFilePos(str string) (*FilePos, error)

Parse fmt: <filename:line?:col?>. Accepts escapes but doesn't unescape.

func (*FilePos) HasOffset

func (fp *FilePos) HasOffset() bool

type Node added in v1.3.3

type Node interface{}

type PosFunc added in v1.3.3

type PosFunc func(int, int) bool

type ResParser2

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

type Resource

type Resource struct {
	Path         string
	RawPath      string
	Line, Column int

	ExpandedMin, ExpandedMax int
	PathSep                  rune
	Escape                   rune
	ParseVolume              bool
}

parsed formats:

<filename:line?:col?>
<filename:#offset> # TODO
file://<filename:line?:col?> # filename should be absolute starting with "/"

func ParseResource

func ParseResource(rd iorw.ReaderAt, index int) (*Resource, error)

func ParseResource2

func ParseResource2(rd iorw.ReaderAt, index int, sep, esc rune, parseVolume bool) (*Resource, error)

type RuneFunc added in v1.3.3

type RuneFunc func(rune) bool

type ScanFunc added in v1.3.3

type ScanFunc func() bool

type ScanFuncPtr added in v1.3.3

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

func (*ScanFuncPtr) Ptr added in v1.3.3

func (ptr *ScanFuncPtr) Ptr() bool

func (*ScanFuncPtr) SetPtr added in v1.3.3

func (ptr *ScanFuncPtr) SetPtr(fn ScanFunc)

type Scanner added in v1.3.3

type Scanner struct {
	Pos        int
	Reverse    bool // read direction
	ErrPadSize int

	DebugRead bool
	// contains filtered or unexported fields
}

WARNING: user functions are responsible for rewinding on fail; check sc.Or(...), sc.Optional(...), etc.

func NewScanner added in v1.3.3

func NewScanner() *Scanner

func NewScannerFromBytes added in v1.3.3

func NewScannerFromBytes(src []byte) *Scanner

func NewScannerFromReader added in v1.3.3

func NewScannerFromReader(rd iorw.ReaderAt) *Scanner

func NewScannerFromString added in v1.3.3

func NewScannerFromString(src string) *Scanner

func (*Scanner) And added in v1.3.3

func (sc *Scanner) And(fns ...ScanFunc) bool

func (*Scanner) AndF added in v1.3.3

func (sc *Scanner) AndF(fns ...ScanFunc) ScanFunc

func (*Scanner) Any added in v1.3.3

func (sc *Scanner) Any(valid string) bool

func (*Scanner) AnyF added in v1.3.3

func (sc *Scanner) AnyF(valid string) ScanFunc

func (*Scanner) BuildNode added in v1.3.3

func (sc *Scanner) BuildNode(fn, trueFn ScanFunc) bool

func (*Scanner) BuildNodeF added in v1.3.3

func (sc *Scanner) BuildNodeF(fn, trueFn ScanFunc) ScanFunc

func (*Scanner) BuildPosNode added in v1.3.3

func (sc *Scanner) BuildPosNode(fn ScanFunc, trueFn PosFunc) bool

func (*Scanner) BuildPosNodeF added in v1.3.3

func (sc *Scanner) BuildPosNodeF(fn ScanFunc, trueFn PosFunc) ScanFunc

func (*Scanner) Byte added in v1.3.3

func (sc *Scanner) Byte(b byte) bool

func (*Scanner) ByteF added in v1.3.3

func (sc *Scanner) ByteF(b byte) ScanFunc

func (*Scanner) ByteFn added in v1.3.3

func (sc *Scanner) ByteFn(fn ByteFunc) bool

func (*Scanner) ByteFnF added in v1.3.3

func (sc *Scanner) ByteFnF(fn ByteFunc) ScanFunc

func (*Scanner) ByteRange added in v1.3.3

func (sc *Scanner) ByteRange(b1, b2 byte) bool

func (*Scanner) ByteRangeF added in v1.3.3

func (sc *Scanner) ByteRangeF(b1, b2 byte) ScanFunc

func (*Scanner) BytesNode added in v1.3.3

func (sc *Scanner) BytesNode(fn ScanFunc) bool

func (*Scanner) BytesNodeF added in v1.3.3

func (sc *Scanner) BytesNodeF(fn ScanFunc) ScanFunc

func (*Scanner) BytesValue added in v1.3.3

func (sc *Scanner) BytesValue(fn ScanFunc) ([]byte, bool)

func (*Scanner) CtxString added in v1.3.3

func (sc *Scanner) CtxString() string

func (*Scanner) Digits added in v1.3.3

func (sc *Scanner) Digits() bool

func (*Scanner) DoubleQuotedString added in v1.3.3

func (sc *Scanner) DoubleQuotedString(escape byte) bool

func (*Scanner) DoubleQuotedStringF added in v1.3.3

func (sc *Scanner) DoubleQuotedStringF(escape byte) ScanFunc

func (*Scanner) End added in v1.3.3

func (sc *Scanner) End() bool

func (*Scanner) EscapedRune added in v1.3.3

func (sc *Scanner) EscapedRune(escape byte) bool

func (*Scanner) EscapedRuneF added in v1.3.3

func (sc *Scanner) EscapedRuneF(escape byte) ScanFunc

func (*Scanner) EscapedRuneFn added in v1.3.3

func (sc *Scanner) EscapedRuneFn(escape byte, fn RuneFunc) bool

func (*Scanner) EscapedRuneFnF added in v1.3.3

func (sc *Scanner) EscapedRuneFnF(escape byte, fn RuneFunc) ScanFunc

func (*Scanner) Except added in v1.3.3

func (sc *Scanner) Except(invalid string) bool

func (*Scanner) ExceptF added in v1.3.3

func (sc *Scanner) ExceptF(invalid string) ScanFunc

func (*Scanner) ExpandReverse added in v1.3.3

func (sc *Scanner) ExpandReverse(fn ScanFunc) bool

func (*Scanner) ExpandReverseF added in v1.3.3

func (sc *Scanner) ExpandReverseF(fn ScanFunc) ScanFunc

func (*Scanner) Float added in v1.3.3

func (sc *Scanner) Float() bool

func (*Scanner) Float64Node added in v1.3.3

func (sc *Scanner) Float64Node(fn ScanFunc) bool

func (*Scanner) Float64NodeF added in v1.3.3

func (sc *Scanner) Float64NodeF(fn ScanFunc) ScanFunc

func (*Scanner) Float64Value added in v1.3.3

func (sc *Scanner) Float64Value(fn ScanFunc) (float64, bool)

func (*Scanner) FnOnTrue added in v1.3.3

func (sc *Scanner) FnOnTrue(fn, trueFn ScanFunc) bool

func (*Scanner) FnOnTrueF added in v1.3.3

func (sc *Scanner) FnOnTrueF(fn, trueFn ScanFunc) ScanFunc

func (*Scanner) GoQuotes added in v1.3.3

func (sc *Scanner) GoQuotes(escape byte, maxLen, maxLenSingleQuote int) bool

func (*Scanner) GoQuotesF added in v1.3.3

func (sc *Scanner) GoQuotesF(escape byte, maxLen, maxLenSingleQuote int) ScanFunc

func (*Scanner) Hexadecimal added in v1.3.3

func (sc *Scanner) Hexadecimal() bool

func (*Scanner) Id1 added in v1.3.3

func (sc *Scanner) Id1() bool

func (*Scanner) IntNode added in v1.3.3

func (sc *Scanner) IntNode(fn ScanFunc) bool

func (*Scanner) IntNodeF added in v1.3.3

func (sc *Scanner) IntNodeF(fn ScanFunc) ScanFunc

func (*Scanner) IntValue added in v1.3.3

func (sc *Scanner) IntValue(fn ScanFunc) (int, bool)

func (*Scanner) Integer added in v1.3.3

func (sc *Scanner) Integer() bool

func (*Scanner) LineComment added in v1.3.3

func (sc *Scanner) LineComment() bool

func (*Scanner) Loop added in v1.3.3

func (sc *Scanner) Loop(fn ScanFunc) bool

Usage example when building slices

func() bool {
	res:=[]int{}
	return sc.FnOnTrue(
		sc.LoopF(func() bool{ res=append(res, ...) ...}),
		func()bool{
			sc.PushBackNode(res) // only on true
		},
	)
}

func (*Scanner) LoopAnyExceptSpaces added in v1.3.3

func (sc *Scanner) LoopAnyExceptSpaces(escape byte) bool

func (*Scanner) LoopAnyExceptSpacesF added in v1.3.3

func (sc *Scanner) LoopAnyExceptSpacesF(escape byte) ScanFunc

func (*Scanner) LoopAnyToNewlineExcludeOrEnd added in v1.3.3

func (sc *Scanner) LoopAnyToNewlineExcludeOrEnd() bool

func (*Scanner) LoopAnyToNewlineIncludeOrEnd added in v1.3.3

func (sc *Scanner) LoopAnyToNewlineIncludeOrEnd() bool

func (*Scanner) LoopAnyToNewlineIncludeOrEndWithEscapes added in v1.3.3

func (sc *Scanner) LoopAnyToNewlineIncludeOrEndWithEscapes(escape byte) bool

func (*Scanner) LoopF added in v1.3.3

func (sc *Scanner) LoopF(fn ScanFunc) ScanFunc

func (*Scanner) LoopRuneFn added in v1.3.3

func (sc *Scanner) LoopRuneFn(fn RuneFunc) bool

func (*Scanner) LoopRuneFnF added in v1.3.3

func (sc *Scanner) LoopRuneFnF(fn RuneFunc) ScanFunc

func (*Scanner) LoopSep added in v1.3.3

func (sc *Scanner) LoopSep(fn, sepFn ScanFunc) bool

func (*Scanner) LoopSepF added in v1.3.3

func (sc *Scanner) LoopSepF(fn, sepFn ScanFunc) ScanFunc

func (*Scanner) LoopUntil added in v1.3.3

func (sc *Scanner) LoopUntil(maxN int, fn, untilFn ScanFunc) bool

func (*Scanner) LoopUntilF added in v1.3.3

func (sc *Scanner) LoopUntilF(maxN int, fn, untilFn ScanFunc) ScanFunc

func (*Scanner) MultiLineComment added in v1.3.3

func (sc *Scanner) MultiLineComment() bool

func (*Scanner) NRunes added in v1.3.3

func (sc *Scanner) NRunes(n int) bool

func (*Scanner) NRunesF added in v1.3.3

func (sc *Scanner) NRunesF(n int) ScanFunc

func (*Scanner) NodeQLen added in v1.3.3

func (sc *Scanner) NodeQLen() int

func (*Scanner) Optional added in v1.3.3

func (sc *Scanner) Optional(fn ScanFunc) bool

func (*Scanner) OptionalF added in v1.3.3

func (sc *Scanner) OptionalF(fn ScanFunc) ScanFunc

func (*Scanner) Or added in v1.3.3

func (sc *Scanner) Or(fns ...ScanFunc) bool

func (*Scanner) OrF added in v1.3.3

func (sc *Scanner) OrF(fns ...ScanFunc) ScanFunc

func (*Scanner) PeekRune added in v1.3.3

func (sc *Scanner) PeekRune() (rune, error)

func (*Scanner) Pointer added in v1.3.3

func (sc *Scanner) Pointer() ScanFuncPtr

usage: a := sc.Pointer(); sc.And(a.Ptr); ... ; a.SetPtr(...)

func (*Scanner) PopFrontNode added in v1.3.3

func (sc *Scanner) PopFrontNode() Node

func (*Scanner) PosFnOnTrue added in v1.3.3

func (sc *Scanner) PosFnOnTrue(fn ScanFunc, trueFn PosFunc) bool

func (*Scanner) PosFnOnTrueF added in v1.3.3

func (sc *Scanner) PosFnOnTrueF(fn ScanFunc, trueFn PosFunc) ScanFunc

func (*Scanner) PrintPosF added in v1.3.3

func (sc *Scanner) PrintPosF(fn ScanFunc) ScanFunc

func (*Scanner) PrintlnF added in v1.3.3

func (sc *Scanner) PrintlnF(v bool, s string) ScanFunc

func (*Scanner) PushBackNode added in v1.3.3

func (sc *Scanner) PushBackNode(node Node)

func (*Scanner) QuotedString added in v1.3.3

func (sc *Scanner) QuotedString(quote rune, escape byte, failOnNewline bool, maxLen int) bool

func (*Scanner) QuotedString2 added in v1.3.3

func (sc *Scanner) QuotedString2(validQuotes string, escape byte, failOnNewline bool, maxLen int) bool

func (*Scanner) QuotedString2F added in v1.3.3

func (sc *Scanner) QuotedString2F(validQuotes string, escape byte, failOnNewline bool, maxLen int) ScanFunc

func (*Scanner) QuotedStringF added in v1.3.3

func (sc *Scanner) QuotedStringF(quote rune, escape byte, failOnNewline bool, maxLen int) ScanFunc

func (*Scanner) ReadByte added in v1.3.3

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

func (*Scanner) ReadRune added in v1.3.3

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

func (*Scanner) Reset added in v1.3.3

func (sc *Scanner) Reset()

func (*Scanner) ResetErrors added in v1.3.3

func (sc *Scanner) ResetErrors()

func (*Scanner) ResetNodeQ added in v1.3.3

func (sc *Scanner) ResetNodeQ()

func (*Scanner) ResetPos added in v1.3.3

func (sc *Scanner) ResetPos()

func (*Scanner) Result added in v1.3.3

func (sc *Scanner) Result(mainFn ScanFunc) (Node, error)

func (*Scanner) Rewind added in v1.3.3

func (sc *Scanner) Rewind(fn ScanFunc) bool

func (*Scanner) RewindF added in v1.3.3

func (sc *Scanner) RewindF(fn ScanFunc) ScanFunc

func (*Scanner) RewindOnFalse added in v1.3.3

func (sc *Scanner) RewindOnFalse(fn ScanFunc) bool

func (*Scanner) RewindOnFalseF added in v1.3.3

func (sc *Scanner) RewindOnFalseF(fn ScanFunc) ScanFunc

func (*Scanner) Rune added in v1.3.3

func (sc *Scanner) Rune(ru rune) bool

func (*Scanner) RuneF added in v1.3.3

func (sc *Scanner) RuneF(ru rune) ScanFunc

func (*Scanner) RuneFn added in v1.3.3

func (sc *Scanner) RuneFn(fn RuneFunc) bool

func (*Scanner) RuneFnF added in v1.3.3

func (sc *Scanner) RuneFnF(fn RuneFunc) ScanFunc

func (*Scanner) RuneNotFn added in v1.3.3

func (sc *Scanner) RuneNotFn(fn RuneFunc) bool

func (*Scanner) RuneNotFnF added in v1.3.3

func (sc *Scanner) RuneNotFnF(fn RuneFunc) ScanFunc

func (*Scanner) RunePeek added in v1.3.3

func (sc *Scanner) RunePeek(ru rune) bool

func (*Scanner) RunePeekF added in v1.3.3

func (sc *Scanner) RunePeekF(ru rune) ScanFunc

func (*Scanner) RuneRange added in v1.3.3

func (sc *Scanner) RuneRange(ru1, ru2 rune) bool

func (*Scanner) RuneRangeF added in v1.3.3

func (sc *Scanner) RuneRangeF(ru1, ru2 rune) ScanFunc

func (*Scanner) Section added in v1.3.3

func (sc *Scanner) Section(open, close string, escape byte, failOnNewline bool, maxLen int, eofClose bool) bool

func (*Scanner) SectionF added in v1.3.3

func (sc *Scanner) SectionF(open, close string, escape byte, failOnNewline bool, maxLen int, eofClose bool) ScanFunc

func (*Scanner) Sequence added in v1.3.3

func (sc *Scanner) Sequence(s string) bool

func (*Scanner) SequenceExpand added in v1.3.3

func (sc *Scanner) SequenceExpand(s string) bool

func (*Scanner) SequenceExpandF added in v1.3.3

func (sc *Scanner) SequenceExpandF(seq string) ScanFunc

func (*Scanner) SequenceF added in v1.3.3

func (sc *Scanner) SequenceF(seq string) ScanFunc

func (*Scanner) SetBytes added in v1.3.3

func (sc *Scanner) SetBytes(b []byte)

func (*Scanner) SetReader added in v1.3.3

func (sc *Scanner) SetReader(rd iorw.ReaderAt)

func (*Scanner) SetScanErrorf added in v1.3.3

func (sc *Scanner) SetScanErrorf(f string, args ...interface{})

func (*Scanner) SetStopErrorf added in v1.3.3

func (sc *Scanner) SetStopErrorf(f string, args ...interface{})

func (*Scanner) SingleNode added in v1.3.3

func (sc *Scanner) SingleNode(fn ScanFunc) bool

Ensures single node on true

func (*Scanner) SingleNodeF added in v1.3.3

func (sc *Scanner) SingleNodeF(fn ScanFunc) ScanFunc

func (*Scanner) SingleQuotedString added in v1.3.3

func (sc *Scanner) SingleQuotedString(escape byte) bool

func (*Scanner) Spaces added in v1.3.3

func (sc *Scanner) Spaces() bool

func (*Scanner) SpacesExceptNewline added in v1.3.3

func (sc *Scanner) SpacesExceptNewline() bool

func (*Scanner) SpacesExceptNewline2 added in v1.3.3

func (sc *Scanner) SpacesExceptNewline2(escape byte) bool

func (*Scanner) SpacesExceptNewline2F added in v1.3.3

func (sc *Scanner) SpacesExceptNewline2F(escape byte) ScanFunc

func (*Scanner) StringNode added in v1.3.3

func (sc *Scanner) StringNode(fn ScanFunc) bool

func (*Scanner) StringNodeF added in v1.3.3

func (sc *Scanner) StringNodeF(fn ScanFunc) ScanFunc

func (*Scanner) StringUnquoteNode added in v1.3.3

func (sc *Scanner) StringUnquoteNode(fn ScanFunc) bool

func (*Scanner) StringUnquoteNodeF added in v1.3.3

func (sc *Scanner) StringUnquoteNodeF(fn ScanFunc) ScanFunc

func (*Scanner) StringUnquoteValue added in v1.3.3

func (sc *Scanner) StringUnquoteValue(fn ScanFunc) (string, bool)

func (*Scanner) StringValue added in v1.3.3

func (sc *Scanner) StringValue(fn ScanFunc) (string, bool)

func (*Scanner) StringValueFn added in v1.3.3

func (sc *Scanner) StringValueFn(fn ScanFunc, trueFn func(string) bool) bool

func (*Scanner) StringValueFnF added in v1.3.3

func (sc *Scanner) StringValueFnF(fn ScanFunc, trueFn func(string) bool) ScanFunc

func (*Scanner) UseReverse added in v1.3.3

func (sc *Scanner) UseReverse(reverse bool, fn ScanFunc) bool

func (*Scanner) UseReverseF added in v1.3.3

func (sc *Scanner) UseReverseF(reverse bool, fn ScanFunc) ScanFunc

type ScannerReader added in v1.3.3

type ScannerReader interface {
	ReadRuneAt(int) (rune, int, error)
	ReadLastRuneAt(int) (rune, int, error)
}

type StopError added in v1.3.3

type StopError struct {
	Pos int
	S   string
}

func (*StopError) Error added in v1.3.3

func (se *StopError) Error() string

Jump to

Keyboard shortcuts

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