strings

package
v0.0.0-...-ab2866d Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: GPL-3.0, GPL-3.0-or-later Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And[S any, B any, M any](
	x p.Combinator[rune, Position, S],
	y p.Combinator[rune, Position, B],
	compose p.Composer[S, B, M],
) p.Combinator[rune, Position, M]

And - use x and y combinators to consume input data. Apply them result to compose function and return result of it.

func Angles

func Angles[T any](
	body p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Angles - parse something between angels characters - '<' and '>'.

func Any

func Any() p.Combinator[rune, Position, rune]

Any - returns the readed item.

func Between

func Between[T any, S any, B any](
	pre p.Combinator[rune, Position, T],
	c p.Combinator[rune, Position, S],
	suf p.Combinator[rune, Position, B],
) p.Combinator[rune, Position, S]

Between - parse sequence of input combinators, skip first and last results.

func Braces

func Braces[T any](
	body p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Braces - parse something between braces characters - '{' and '}'.

func Buffer

func Buffer(data []rune, newLineRunes ...rune) *buffer

Buffer - make buffer which can read text on input and use struct for positions.

func Cast

func Cast[T any, S any](
	c p.Combinator[rune, Position, T],
	f func(T) (S, error),
) p.Combinator[rune, Position, S]

Cast - parse data by c combinator and apply to f function. Return result of f function.

func Chainl

func Chainl[T any](
	c p.Combinator[rune, Position, T],
	op p.Combinator[rune, Position, func(T, T) T],
	def T,
) p.Combinator[rune, Position, T]

Chainl - read zero or more occurrences of data readed by c combinator, separated by op combinator. Returns a value obtained by a left associative application of all functions returned by op combinator to the values returned by c combinator. If nothing read, the value def is returned.

func Chainl1

func Chainl1[T any](
	c p.Combinator[rune, Position, T],
	op p.Combinator[rune, Position, func(T, T) T],
) p.Combinator[rune, Position, T]

Chainl1 - read one or more occurrences of data readed by c combinator, separated by data readed by op combinator. Returns a value obtained by a left associative application of all functions returned by op combinator to the values returned by c combinator. If nothing read, the value def is returned.

func Chainr

func Chainr[T any](
	c p.Combinator[rune, Position, T],
	op p.Combinator[rune, Position, func(T, T) T],
	def T,
) p.Combinator[rune, Position, T]

Chainr - read zero or more occurrences of data readed by c combinator, separated by op combinator. Returns a value obtained by a right associative application of all functions returned by op to the values returned by c combinator. If nothing read, the value def is returned.

func Chainr1

func Chainr1[T any](
	c p.Combinator[rune, Position, T],
	op p.Combinator[rune, Position, func(T, T) T],
) p.Combinator[rune, Position, T]

Chainr - read one or more occurrences of data readed by c combinator, separated by op combinator. Returns a value obtained by a right associative application of all functions returned by op to the values returned by c combinator. If nothing read, the value def is returned.

func Choice

func Choice[T any](
	cs ...p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Choice - searches for a combinator that works successfully on the input data. if one is not found, it returns an NothingMatched error.

func Colon

func Colon() p.Combinator[rune, Position, rune]

Colon - parse colon character.

func Comma

func Comma() p.Combinator[rune, Position, rune]

Comma - parse comma character.

func Concat

func Concat[T any](
	cap int,
	cs ...p.Combinator[rune, Position, []T],
) p.Combinator[rune, Position, []T]

Concat - use cs combinators to parse slices step by step, concatenate all result to one big slice and returns it.

func Const

func Const[S any](value S) p.Combinator[rune, Position, S]

Const - doesn't read anything, just return the input value.

func Count

func Count[T any](
	n int,
	c p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, []T]

Count - try to read X item by c combinator. Stop on first error.

func Dot

func Dot() p.Combinator[rune, Position, rune]

Dot - parse dot character.

func EOF

func EOF() p.Combinator[rune, Position, bool]

EOF - checks that buffer reading has finished.

func EndBy

func EndBy[T any, S any](
	cap int,
	body p.Combinator[rune, Position, T],
	sep p.Combinator[rune, Position, S],
) p.Combinator[rune, Position, []T]

EndBy - read zero or more occurrences of data readed by c combinator, separated and ended by data readed by sep combinator. Returns a slice of values returned by p.

func EndBy1

func EndBy1[T any, S any](
	cap int,
	body p.Combinator[rune, Position, T],
	sep p.Combinator[rune, Position, S],
) p.Combinator[rune, Position, []T]

EndBy1 - read one or more occurrences of data readed by c combinator, separated and ended by data readed by sep combinator. Returns a slice of values returned by c combinator.

func Eq

func Eq(t rune) p.Combinator[rune, Position, rune]

Eq - succeeds for any item which equal input t. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func Fail

func Fail[S any](err error) p.Combinator[rune, Position, S]

Fail - doesn't read anything, just return input error.

func Gt

func Gt(t rune) p.Combinator[rune, Position, rune]

Gt - succeeds for any item which greater than input value. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func Gte

func Gte(t rune) p.Combinator[rune, Position, rune]

Gte - succeeds for any item which greater than or equal input value. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func IsControl

func IsControl() p.Combinator[rune, Position, rune]

IsControl - parse control UTF-8 characters.

func IsDigit

func IsDigit() p.Combinator[rune, Position, rune]

IsDigit - parse decimal digit UTF-8 characters.

func IsGraphic

func IsGraphic() p.Combinator[rune, Position, rune]

IsGraphic - parse graphic UTF-8 characters.

func IsLetter

func IsLetter() p.Combinator[rune, Position, rune]

IsLetter - parse letter UTF-8 characters.

func IsLower

func IsLower() p.Combinator[rune, Position, rune]

IsLower - parse UTF-8 character in lower case.

func IsMark

func IsMark() p.Combinator[rune, Position, rune]

IsLower - parse mark UTF-8 characters.

func IsNumber

func IsNumber() p.Combinator[rune, Position, rune]

IsNumber - parse UTF-8 number characters.

func IsPrint

func IsPrint() p.Combinator[rune, Position, rune]

IsPrint - parse printable UTF-8 characters.

func IsPunct

func IsPunct() p.Combinator[rune, Position, rune]

IsPunct - parse UTF-8 punctuation character.

func IsSpace

func IsSpace() p.Combinator[rune, Position, rune]

IsSpace - parse UTF-8 space character.

func IsSymbol

func IsSymbol() p.Combinator[rune, Position, rune]

IsSpace - parse UTF-8 symbolic character.

func IsTitle

func IsTitle() p.Combinator[rune, Position, rune]

IsTitle - parse UTF-8 character in title case.

func IsUpper

func IsUpper() p.Combinator[rune, Position, rune]

IsLower - parse UTF-8 character in upper case.

func Lt

func Lt(t rune) p.Combinator[rune, Position, rune]

Lt - succeeds for any item which less than input value. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func Lte

func Lte(t rune) p.Combinator[rune, Position, rune]

Lte - succeeds for any item which less than or equal input value. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func Many

func Many[T any](
	cap int,
	c p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, []T]

Many - accumulate data which returned by c consumer until it possible. Stop on first error or end of buffer. Returns an empty slice even if nothing could be parsed.

func ManyTill

func ManyTill[T any, S any](
	cap int,
	c p.Combinator[rune, Position, T],
	end p.Combinator[rune, Position, S],
) p.Combinator[rune, Position, []T]

ManyTill - accumulate data readed by c combinator until combinantor end succeeds. Returns a slice of values returned by body combinator.

func Map

func Map[K comparable, V any](
	cases map[K]V,
	c p.Combinator[rune, Position, K],
) p.Combinator[rune, Position, V]

Map - Reads one element from the input buffer using the combinator, then uses the resulting element to obtain a value from the map cases and try to match it in cases map passed by first argument. If the value is not found then it returns NothingMatched error.

func MapStrings

func MapStrings[V any](
	cases map[string]V,
) p.Combinator[rune, Position, V]

MapStrings - Reads text from the input buffer using the combinator and match it in on the fly by cases map passed by first argument. If the value is not found then it returns NothingMatched error. This combinator use special trie-like structure for text matching.

func NoneOf

func NoneOf(data ...rune) p.Combinator[rune, Position, rune]

NoneOf - succeeds for any item which not included in input data. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func NotEq

func NotEq(t rune) p.Combinator[rune, Position, rune]

NotEq - succeeds for any item which not equal input t. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func NotRange

func NotRange(from rune, to rune) p.Combinator[rune, Position, rune]

NotRange - succeeds for any item which not included in input range. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func OneOf

func OneOf(data ...rune) p.Combinator[rune, Position, rune]

OneOf - succeeds for any item which included in input data. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func OneOfStrings

func OneOfStrings(strs ...string) p.Combinator[rune, Position, string]

OneOfStrings - succeeds for any item which included in input data. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func Optional

func Optional[T any](
	c p.Combinator[rune, Position, T],
	def T,
) p.Combinator[rune, Position, T]

Optional - use c combinator to consume input data from buffer. If it failed, than return def value.

func Or

func Or[T any](
	x p.Combinator[rune, Position, T],
	y p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Or - returns the result of the first combinator, if it fails, uses the second combinator.

func Padded

func Padded[T any, S any](
	skip p.Combinator[rune, Position, S],
	body p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Padded - skip sequence of items parsed by first combinator before and after body combinator.

func Parens

func Parens[T any](
	body p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Parens - parse something between parens characters - '(' and ')'.

func Parse

func Parse[T any](
	data []rune,
	parse p.Combinator[rune, Position, T],
) (T, error)

Parse - parse text by c combinator.

func ParseString

func ParseString[T any](
	str string,
	parse p.Combinator[rune, Position, T],
) (T, error)

ParseString - parse text by c combinator.

func Range

func Range(from rune, to rune) p.Combinator[rune, Position, rune]

Range - succeeds for any item which include in input range. Returns the item that is actually readed from input buffer. Greedy by default - keep position after reading.

func Satisfy

func Satisfy(
	greedy bool,
	f p.Condition[rune],
) p.Combinator[rune, Position, rune]

Satisfy - succeeds for any item for which the supplied function f returns true. Returns the item that is actually readed from input buffer. if greedy buffer keep position after reading.

func Semi

func Semi() p.Combinator[rune, Position, rune]

Semi - parse semi character.

func SepBy

func SepBy[T any, S any](
	cap int,
	body p.Combinator[rune, Position, T],
	sep p.Combinator[rune, Position, S],
) p.Combinator[rune, Position, []T]

SepBy - read zero or more occurrences of data readed by c combinator, separated by sep combinator. Returns a slice of values returned by p.

func SepBy1

func SepBy1[T any, S any](
	cap int,
	body p.Combinator[rune, Position, T],
	sep p.Combinator[rune, Position, S],
) p.Combinator[rune, Position, []T]

SepBy1 - read one or more occurrences of data readed by c combinator, separated by sep combinator. Returns a slice of values returned by p.

func SepEndBy

func SepEndBy[T any, S any](
	cap int,
	body p.Combinator[rune, Position, T],
	sep p.Combinator[rune, Position, S],
) p.Combinator[rune, Position, []T]

SepEndBy - read zero or more occurrences of data readed by body combinator, separated and optionally ended by data readed by sep combinator. Returns a slice of values returned by body combinator.

func SepEndBy1

func SepEndBy1[T any, S any](
	cap int,
	body p.Combinator[rune, Position, T],
	sep p.Combinator[rune, Position, S],
) p.Combinator[rune, Position, []T]

SepEndBy1 - read one or more occurrences of data readed by body combinator, separated and optionally ended by data readed by sep combinator. Returns a slice of values returned by body combinator.

func Sequence

func Sequence[T any](
	cap int,
	cs ...p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, []T]

Sequence - reads input elements one by one using cs combinators. If any of them fails, it returns an error.

func SequenceOf

func SequenceOf(data ...rune) p.Combinator[rune, Position, []rune]

SequenceOf - expects a sequence of elements in the buffer equal to the input data sequence. If expectations are not met, returns NothingMatched error.

func Skip

func Skip[T any, S any](
	skip p.Combinator[rune, Position, S],
	body p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Skip - ignores the result of the first combinator and returns only the result of the second.

func SkipAfter

func SkipAfter[T any, S any](
	skip p.Combinator[rune, Position, S],
	body p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

SkipAfter - ignores the result of the first combinator and returns only the result of the second. Use body combinator at first.

func SkipMany

func SkipMany[T any, S any](
	skip p.Combinator[rune, Position, S],
	body p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

SkipMany - skip sequence of items parsed by first combinator before body combinator.

func Some

func Some[T any](
	cap int,
	c p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, []T]

Some - accumulate data which returned by c consumer until it possible. Stop on first error or end of buffer. Returns an error if at least one element could not be read.

func Squares

func Squares[T any](
	body p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Squares - parse something between squares characters - '[' and ']'.

func String

func String(str string) p.Combinator[rune, Position, string]

String - read input text and match with string passed by first argument. If the text not matched then it returns NothingMatched error.

func TimeZone

func TimeZone(
	locations ...*time.Location,
) p.Combinator[rune, Position, *time.Location]

TimeZone - parse one of time zones from passed arguments.

func TimeZoneByNames

func TimeZoneByNames(
	locationNames ...string,
) (p.Combinator[rune, Position, *time.Location], error)

TimeZoneByNames - parse one of time zones from passed arguments.

func Trace

func Trace[T any](
	l p.Logged,
	m string,
	c p.Combinator[rune, Position, T],
) p.Combinator[rune, Position, T]

Trace - writes messages to the log about the state of the buffer before and after using the combinator, the result of the cobinator and its error.

func Try

func Try[T any](c p.Combinator[rune, Position, T]) p.Combinator[rune, Position, T]

Try - try to use c combinator, if it falls, it returns buffer to the previous position.

func Unsigned

func Unsigned[T constraints.Integer]() p.Combinator[rune, Position, T]

Unsigned - parse unsigned integer.

func UnsignedN

func UnsignedN[T constraints.Integer](n int) p.Combinator[rune, Position, T]

UnsignedN - parse unsigned integer with N count of digits.

Types

type Position

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

Position - position in text.

func (Position) Column

func (p Position) Column() uint

Column - column number.

func (Position) Line

func (p Position) Line() uint

Line - line number.

func (Position) String

func (p Position) String() string

String - return string representation of opsition.

Jump to

Keyboard shortcuts

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