Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶
And parses with `parsers`. Succeeds if all parsers succeed, otherwise fails. Returns a slice with all values on success.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/char" "github.com/flier/gocombine/pkg/parser/choice" ) func main() { p := choice.And(char.Digit(), char.Char('i')) fmt.Println(p([]rune("9i456"))) fmt.Println(p([]rune("123"))) }
Output: [57 105] [52 53 54] <nil> [49 50] [51] and, char, expected 'i', actual '2', unexpected
func Optional ¶
Optional parses `parser` and outputs `Some(value)` if it succeeds, `None` if it fails without consuming any input.
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 := choice.Optional(to.String(char.String("hello"))) fmt.Println(p([]rune("hello"))) fmt.Println(p([]rune("world"))) }
Output: hello [] <nil> <none> [119 111 114 108 100] <nil>
func Or ¶
Or returns a parser which attempts to parse using `parsers`.
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/combinator" "github.com/flier/gocombine/pkg/parser/to" ) func main() { p := choice.Or( to.String(char.String("let")), combinator.Map(char.Digit(), func(r rune) string { return "digit" }), to.String(char.String("led")), ) fmt.Println(p([]rune("let"))) fmt.Println(p([]rune("1"))) fmt.Println(p([]rune("lost"))) }
Output: let [] <nil> digit [] <nil> [115 116] or, 3 errors occurred: * map, string, cmp, expected "let", actual "lo", unexpected * map, digit, satisfy, actual 'l', unexpected * map, string, cmp, expected "led", actual "lo", unexpected
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.