Documentation ¶
Index ¶
- func Checkpoint[T Token](s []T) []T
- func Distance[T Token](cur, end []T) int
- func Empty[T Token](s []T) bool
- func Len[T Token](s []T) int
- func Uncons[T Token](input []T) (tok T, remaining []T, err error)
- func UnconsRange[T Token](input []T, size int) (tokens []T, remaining []T, err error)
- func UnconsUntil[T Token](input []T, predicate func(T) bool) (tokens []T, remaining []T, err error)
- func UnconsWhile[T Token](input []T, predicate func(T) bool) (tokens []T, remaining []T, err error)
- type LineNumber
- type Offset
- type Position
- type Span
- type Token
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Checkpoint ¶
func Checkpoint[T Token](s []T) []T
func Distance ¶
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/stream" ) func main() { input := []rune{'a', 'b'} before := stream.Checkpoint(input) fmt.Println(stream.Distance(input, before)) b, input, err := stream.Uncons(input) if err != nil { panic(err) } fmt.Println(stream.Distance(input, before), b) b, input, err = stream.Uncons(input) if err != nil { panic(err) } fmt.Println(stream.Distance(input, before), b) _, _, err = stream.Uncons(input) fmt.Println(err) }
Output: 0 1 97 2 98 unexpected EOF
func Uncons ¶
Uncons takes a stream `input` and removes its first token, yielding the `tok` and the `remaining` of the elements. Returns `err` if no element could be retrieved.
func UnconsRange ¶
UnconsRange takes `size` elements from the stream. Fails if the length of the stream is less than `size`.
func UnconsUntil ¶
UnconsUntil takes items from stream, testing each one with `predicate`. returns the range of items which not passed `predicate`.
func UnconsWhile ¶
UnconsWhile takes items from stream, testing each one with `predicate`. returns the range of items which passed `predicate`.
Types ¶
type LineNumber ¶
func NewLineNumber ¶
func NewLineNumber[T Token](input []T) *LineNumber
Click to show internal directories.
Click to hide internal directories.