strings

package
v0.0.0-...-13237ec Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 7 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 common.Combinator[rune, Position, S],
	y common.Combinator[rune, Position, B],
	compose common.Composer[S, B, M],
) common.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 common.Combinator[rune, Position, T],
) common.Combinator[rune, Position, T]

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

func Any

Any - returns the readed item.

func Between

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

func Braces

func Braces[T any](
	body common.Combinator[rune, Position, T],
) common.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 common.Combinator[rune, Position, T],
	f func(T) (S, error),
) common.Combinator[rune, Position, S]

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

func Chainl

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

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

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

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 ...common.Combinator[rune, Position, T],
) common.Combinator[rune, Position, T]

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

func Colon

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

Colon - parse colon character.

func Comma

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

Comma - parse comma character.

func Concat

func Concat[T any](
	cap int,
	cs ...common.Combinator[rune, Position, []T],
) common.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) common.Combinator[rune, Position, S]

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

func Control

func Control(errMessage string) common.Combinator[rune, Position, rune]

Control - parse control UTF-8 characters. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Count

func Count[T any](
	cap int,
	errMessage string,
	c common.Combinator[rune, Position, T],
) common.Combinator[rune, Position, []T]

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

func Digit

func Digit(errMessage string) common.Combinator[rune, Position, rune]

Digit - parse decimal digit UTF-8 characters. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Dot

Dot - parse dot character.

func EOF

EOF - checks that buffer reading has finished.

func EndBy

func EndBy[T any, S any](
	cap int,
	body common.Combinator[rune, Position, T],
	sep common.Combinator[rune, Position, S],
) common.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,
	errMessage string,
	body common.Combinator[rune, Position, T],
	sep common.Combinator[rune, Position, S],
) common.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(
	errMessage string,
	t rune,
) common.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](errMessage string) common.Combinator[rune, Position, S]

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

func Graphic

func Graphic(errMessage string) common.Combinator[rune, Position, rune]

Graphic - parse graphic UTF-8 characters. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Gt

func Gt(
	errMessage string,
	t rune,
) common.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(
	errMessage string,
	t rune,
) common.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 Letter

func Letter(errMessage string) common.Combinator[rune, Position, rune]

Letter - parse letter UTF-8 characters. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Lower

func Lower(errMessage string) common.Combinator[rune, Position, rune]

Lower - parse UTF-8 character in lower case. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Lt

func Lt(
	errMessage string,
	t rune,
) common.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(
	errMessage string,
	t rune,
) common.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 common.Combinator[rune, Position, T],
) common.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,
	errMessage string,
	c common.Combinator[rune, Position, T],
	end common.Combinator[rune, Position, S],
) common.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](
	errMessage string,
	cases map[K]V,
	c common.Combinator[rune, Position, K],
) common.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 ParseError error.

func MapStrings

func MapStrings[V any](
	errMessage string,
	cases map[string]V,
) common.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 ParseError error. This combinator use special trie-like structure for text matching.

func Mark

func Mark(errMessage string) common.Combinator[rune, Position, rune]

Lower - parse mark UTF-8 characters. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func NoneOf

func NoneOf(
	errMessage string,
	data ...rune,
) common.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(
	errMessage string,
	r rune,
) common.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(
	errMessage string,
	from, to rune,
) common.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 Number

func Number(errMessage string) common.Combinator[rune, Position, rune]

Number - parse UTF-8 number characters. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func OneOf

func OneOf(
	errMessage string,
	data ...rune,
) common.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 Optional

func Optional[T any](
	c common.Combinator[rune, Position, T],
	def T,
) common.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](
	errMessage string,
	x common.Combinator[rune, Position, T],
	y common.Combinator[rune, Position, T],
) common.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 common.Combinator[rune, Position, S],
	body common.Combinator[rune, Position, T],
) common.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 common.Combinator[rune, Position, T],
) common.Combinator[rune, Position, T]

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

func Parse

func Parse[T any](
	data []rune,
	parse common.Combinator[rune, Position, T],
) (T, common.Error[Position])

Parse - parse text by c combinator.

func ParseString

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

ParseString - parse text by c combinator.

func Print

func Print(errMessage string) common.Combinator[rune, Position, rune]

Print - parse printable UTF-8 characters. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Punct

func Punct(errMessage string) common.Combinator[rune, Position, rune]

Punct - parse UTF-8 punctuation character. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Range

func Range(
	errMessage string,
	from, to rune,
) common.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 RangeTable

func RangeTable(
	errMessage string,
	tbl *unicode.RangeTable,
) common.Combinator[rune, Position, rune]

RangeTable - parse UTF-8 character in upper case. Read more about utf characters tables - https://pkg.go.dev/unicode

func Satisfy

func Satisfy(
	errMessage string,
	greedy bool,
	f common.Condition[rune],
) common.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

Semi - parse semi character.

func SepBy

func SepBy[T any, S any](
	cap int,
	body common.Combinator[rune, Position, T],
	sep common.Combinator[rune, Position, S],
) common.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,
	errMessage string,
	body common.Combinator[rune, Position, T],
	sep common.Combinator[rune, Position, S],
) common.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 common.Combinator[rune, Position, T],
	sep common.Combinator[rune, Position, S],
) common.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,
	errMessage string,
	body common.Combinator[rune, Position, T],
	sep common.Combinator[rune, Position, S],
) common.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 ...common.Combinator[rune, Position, T],
) common.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(
	errMessage string,
	data ...rune,
) common.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 ParseError error.

func Skip

func Skip[T any, S any](
	skip common.Combinator[rune, Position, S],
	body common.Combinator[rune, Position, T],
) common.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 common.Combinator[rune, Position, S],
	body common.Combinator[rune, Position, T],
) common.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 common.Combinator[rune, Position, S],
	body common.Combinator[rune, Position, T],
) common.Combinator[rune, Position, T]

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

func Some

func Some[T any](
	cap int,
	errMessage string,
	c common.Combinator[rune, Position, T],
) common.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 Space

func Space(errMessage string) common.Combinator[rune, Position, rune]

Space - parse UTF-8 space character. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Squares

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

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

func String

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

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

func Symbol

func Symbol(errMessage string) common.Combinator[rune, Position, rune]

Space - parse UTF-8 symbolic character. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func TimeZone

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

TimeZone - parse one of time zones from passed arguments.

func TimeZoneByNames

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

TimeZoneByNames - parse one of time zones from passed arguments.

func Title

func Title(errMessage string) common.Combinator[rune, Position, rune]

Title - parse UTF-8 character in title case. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

func Trace

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

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

func Unsigned

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

Unsigned - parse unsigned integer.

func UnsignedN

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

UnsignedN - parse unsigned integer with N count of digits.

func Upper

func Upper(errMessage string) common.Combinator[rune, Position, rune]

Lower - parse UTF-8 character in upper case. Read more about utf characters tables - https://pkg.go.dev/unicode#pkg-constants

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) Deeper

func (p Position) Deeper(other Position) bool

Deeper - is it deeper position?.

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