bytes

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[byte, int, S],
	y p.Combinator[byte, int, B],
	compose p.Composer[S, B, M],
) p.Combinator[byte, int, M]

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

func Any

func Any() p.Combinator[byte, int, byte]

Any - returns the readed byte.

func Between

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

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

func Buffer

func Buffer(data []byte) *buffer

Buffer - make buffer which can read bytes on input and use integer for positions.

func BufferFromFile

func BufferFromFile(path string) (*buffer, error)

Buffer - read file and make buffer which can read bytes on input and use integer for positions.

func Cast

func Cast[T any, S any](
	c p.Combinator[byte, int, T],
	f func(T) (S, error),
) p.Combinator[byte, int, 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[byte, int, T],
	op p.Combinator[byte, int, func(T, T) T],
	def T,
) p.Combinator[byte, int, T]

Chainl - read zero or more occurrences of byte 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[byte, int, T],
	op p.Combinator[byte, int, func(T, T) T],
) p.Combinator[byte, int, T]

Chainl1 - read one or more occurrences of byte 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[byte, int, T],
	op p.Combinator[byte, int, func(T, T) T],
	def T,
) p.Combinator[byte, int, T]

Chainr - read zero or more occurrences of byte 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[byte, int, T],
	op p.Combinator[byte, int, func(T, T) T],
) p.Combinator[byte, int, T]

Chainr - read one or more occurrences of byte 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[byte, int, T],
) p.Combinator[byte, int, T]

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

func Concat

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

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

func Count

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

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

func EOF

func EOF() p.Combinator[byte, int, bool]

EOF - checks that buffer reading has finished.

func EndBy

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

EndBy - read zero or more occurrences of byte 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[byte, int, T],
	sep p.Combinator[byte, int, S],
) p.Combinator[byte, int, []T]

EndBy1 - read one or more occurrences of byte 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 byte) p.Combinator[byte, int, byte]

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

func Fail

func Fail[S any](err error) p.Combinator[byte, int, S]

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

func Gt

func Gt(t byte) p.Combinator[byte, int, byte]

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

func Gte

func Gte(t byte) p.Combinator[byte, int, byte]

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

func Lt

func Lt(t byte) p.Combinator[byte, int, byte]

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

func Lte

func Lte(t byte) p.Combinator[byte, int, byte]

Lte - succeeds for any byte which less than or equal input byte. Returns the byte 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[byte, int, T],
) p.Combinator[byte, int, []T]

Many - read bytes and 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[byte, int, T],
	end p.Combinator[byte, int, S],
) p.Combinator[byte, int, []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[byte, int, K],
) p.Combinator[byte, int, V]

Map - Reads one element from the bytes buffer using the combinator, then uses the resulting element to obtain a value from the map cases and returns it. If the value is not found then it returns NothingMatched error.

func NoneOf

func NoneOf(data ...byte) p.Combinator[byte, int, byte]

NoneOf - succeeds for any byte 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 byte) p.Combinator[byte, int, byte]

NotEq - succeeds for any byte 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 byte, to byte) p.Combinator[byte, int, byte]

NotRange - succeeds for any byte 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 ...byte) p.Combinator[byte, int, byte]

OneOf - succeeds for any byte 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[byte, int, T],
	def T,
) p.Combinator[byte, int, T]

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

func Or

func Or[T any](
	x p.Combinator[byte, int, T],
	y p.Combinator[byte, int, T],
) p.Combinator[byte, int, 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[byte, int, S],
	body p.Combinator[byte, int, T],
) p.Combinator[byte, int, T]

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

func Parse

func Parse[T any](data []byte, parse common.Combinator[byte, int, T]) (T, error)

Parse - parse bytes from input slice by c combinator.

func ParseFile

func ParseFile[T any](path string, parse common.Combinator[byte, int, T]) (T, error)

ParseFile - parse bytes from file by c combinator.

func Range

func Range(from byte, to byte) p.Combinator[byte, int, byte]

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

func ReadAs

func ReadAs[T Number](
	n int,
	order binary.ByteOrder,
) p.Combinator[byte, int, T]

ReadAs - read n of bytes, decode it in binary order passed by second argument and return it.

func Satisfy

func Satisfy(
	greedy bool,
	f p.Condition[byte],
) p.Combinator[byte, int, byte]

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

func SepBy

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

SepBy - read zero or more occurrences of byte 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[byte, int, T],
	sep p.Combinator[byte, int, S],
) p.Combinator[byte, int, []T]

SepBy1 - read one or more occurrences of byte 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[byte, int, T],
	sep p.Combinator[byte, int, S],
) p.Combinator[byte, int, []T]

SepEndBy - read zero or more occurrences of byte 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[byte, int, T],
	sep p.Combinator[byte, int, S],
) p.Combinator[byte, int, []T]

SepEndBy1 - read one or more occurrences of byte 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[byte, int, T],
) p.Combinator[byte, int, []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 ...byte) p.Combinator[byte, int, []byte]

SequenceOf - expects a sequence of bytes 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[byte, int, S],
	body p.Combinator[byte, int, T],
) p.Combinator[byte, int, 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[byte, int, S],
	body p.Combinator[byte, int, T],
) p.Combinator[byte, int, T]

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

func Some

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

Some - read bytes and 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 Trace

func Trace[T any](
	l p.Logged,
	m string,
	c p.Combinator[rune, int, T],
) p.Combinator[rune, int, 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[byte, int, T]) p.Combinator[byte, int, T]

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

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Jump to

Keyboard shortcuts

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