to

package
v0.0.0-...-1dacd80 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool[T stream.Token, O StringLike](parser parser.Func[T, O]) parser.Func[T, bool]

Bool convert the result of `parser` to a bool.

Example
package main

import (
	"fmt"

	"github.com/flier/gocombine/pkg/parser/char"
	"github.com/flier/gocombine/pkg/parser/choice"
	"github.com/flier/gocombine/pkg/parser/to"
)

func main() {
	p := to.Bool(choice.Or(
		to.String(char.Fold("true")),
		to.String(char.Fold("false")),
		to.String(char.OneOf("tTfF10")),
	))

	fmt.Println(p([]rune("t")))
	fmt.Println(p([]rune("0")))
	fmt.Println(p([]rune("True")))
	fmt.Println(p([]rune("FALSE")))

}
Output:

true [] <nil>
false [] <nil>
true [] <nil>
false [] <nil>

func Float

func Float[T stream.Token, O StringLike](parser parser.Func[T, O]) parser.Func[T, float64]

Float convert the result of `parser` to a float64.

Example
package main

import (
	"fmt"

	"github.com/flier/gocombine/pkg/parser/char"
	"github.com/flier/gocombine/pkg/parser/to"
)

func main() {
	p := to.Float(char.Float())

	fmt.Println(p([]rune("3.1415926535")))
	fmt.Println(p([]rune("NaN")))
	fmt.Println(p([]rune("nan")))
	fmt.Println(p([]rune("inf")))
	fmt.Println(p([]rune("+Inf")))
	fmt.Println(p([]rune("-Inf")))
	fmt.Println(p([]rune("-0")))
	fmt.Println(p([]rune("+0")))

}
Output:

3.1415926535 [] <nil>
NaN [] <nil>
NaN [] <nil>
+Inf [] <nil>
+Inf [] <nil>
-Inf [] <nil>
-0 [] <nil>
0 [] <nil>

func Int

func Int[T stream.Token, O StringLike](p parser.Func[T, O]) parser.Func[T, int]

Int parses a string-like data and converts it to an integer.

Example
package main

import (
	"fmt"

	"github.com/flier/gocombine/pkg/parser/char"
	"github.com/flier/gocombine/pkg/parser/repeat"
	"github.com/flier/gocombine/pkg/parser/to"
)

func main() {
	p := to.Int(repeat.Many1(char.Digit()))

	fmt.Println(p([]rune("123abc")))

}
Output:

123 [97 98 99] <nil>

func Str

func Str[S StringLike](s S) string

Str convert a `StringLike` type to a string.

func String

func String[T stream.Token, O StringLike](parser parser.Func[T, O]) parser.Func[T, string]

String convert the result of `parser` to a string.

func StringSlice

func StringSlice[T stream.Token, O StringLike](parser parser.Func[T, []O]) parser.Func[T, []string]

StringSlice convert the result of `parser` to a string slice.

Types

type StringLike

type StringLike interface {
	byte | rune | []byte | []rune | []uint16 | string
}

StringLike constraints for the types that can be converted to string.

Jump to

Keyboard shortcuts

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