parse

package
v0.0.53 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

Letter returns a parser which accepts a rune within the Letter Unicode range.

View Source
var ZeroToNine = RuneIn("0123456789")

ZeroToNine returns a parser which accepts a rune within range, i.e. 0-9.

Functions

func WithIntegerCombiner

func WithIntegerCombiner(items []interface{}) (item interface{}, value bool)

WithIntegerCombiner is a MultipleResultCombiner which concatenates the results together as a string then parses the result as an integer.

func WithStringConcatCombiner

func WithStringConcatCombiner(inputs []interface{}) (interface{}, bool)

WithStringConcatCombiner is a MultipleResultCombiner which concatenates the results together as a string.

Types

type Function

type Function func(Input) Result

Function represents the state of the scanner as a function that returns the next state.

func All

func All(combiner MultipleResultCombiner, functions ...Function) Function

All ensures that all of the parsers are captured, or winds the whole set of captures back.

func Any

func Any(functions ...Function) Function

Any returns the first match out of the parse functions passed in, or a failure if no parsers match.

func AnyRune

func AnyRune() Function

AnyRune returns a parser which will parse any rune at all.

func AtLeast

func AtLeast(combiner MultipleResultCombiner, times int, f Function) Function

AtLeast captures the passed function at least the number of times provided.

func AtMost

func AtMost(combiner MultipleResultCombiner, times int, f Function) Function

AtMost captures the passed function between one and the number of times provided.

func Many

func Many(combiner MultipleResultCombiner, atLeast, atMost int, f Function) Function

Many captures the function at least x times and at most y times and sets the result item to an array of the function captures.

func Optional

func Optional(combiner MultipleResultCombiner, f Function) Function

Optional provides an optional parser.

func Or

func Or(a, b Function) Function

Or returns the first or a or b. It's equivalent to the Any function with two parameters.

func Rune

func Rune(r rune) Function

Rune captures a single, specified rune.

func RuneIn

func RuneIn(set string) Function

RuneIn captures a rune if it's within the input set.

func RuneInRanges

func RuneInRanges(rts ...*unicode.RangeTable) Function

RuneInRanges returns a parser which accepts a rune within the specified Unicode range.

func RuneNotIn

func RuneNotIn(set string) Function

RuneNotIn captures a rune if it's not within the input set.

func RuneWhere

func RuneWhere(predicate func(r rune) bool) Function

RuneWhere captures a rune which matches a predicate.

func String

func String(s string) Function

String captures a specific string.

func StringInsensitive added in v0.0.47

func StringInsensitive(s string) Function

StringInsensitive tests whether the string is present, but ignoring string casing.

func StringUntil

func StringUntil(delimiter Function) Function

StringUntil captures runes until the delimiter is encountered and returns a string.

func StringUntilDelimiterOrEOF added in v0.0.53

func StringUntilDelimiterOrEOF(delimiter Function) Function

func Then

func Then(combiner MultipleResultCombiner, a, b Function) Function

Then executes one function, then another, comining the results using the provided function.

func Times

func Times(combiner MultipleResultCombiner, times int, f Function) Function

Times captures the parser function a set number of times.

type Input

type Input interface {
	// Collect collects all of the string data parsed so far and returns it, then starts a new collection
	// from the current position in the input.
	Collect() string
	// Advance advances the input by a single rune and consumes it.
	Advance() (rune, error)
	// Retreat retreats the input position by a single rune and unconsumes it.
	Retreat() (rune, error)
	// Peek returns the next rune from the input without consuming it.
	Peek() (rune, error)
	// Position returns the line and column number of the current position within the stream.
	Position() (line, column int)
	// Index returns the current index of the parser input.
	Index() int64
}

Input represents the input to a parser.

type MultipleResultCombiner

type MultipleResultCombiner func([]interface{}) (result interface{}, ok bool)

MultipleResultCombiner combines the results from multiple parse operations into a single result.

type Result

type Result struct {
	Name    string
	Success bool
	Item    interface{}
	Error   error
}

Result is the result of a parse operation.

func Failure

func Failure(name string, err error) Result

Failure creates an unsuccessful result of a parse operation.

func Success

func Success(name string, item interface{}, err error) Result

Success creates a successful result of a parse operation.

func (Result) Eq

func (result Result) Eq(cmp Result) bool

Eq compares two results for equality.

func (Result) String

func (result Result) String() string

String returns the string representation of a result, truncated to 10 characters.

Jump to

Keyboard shortcuts

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