Documentation ¶
Index ¶
- func AlphaNum() parser.Func[byte, byte]
- func Any() parser.Func[byte, byte]
- func Byte(b byte) parser.Func[byte, byte]
- func Bytes(s []byte) parser.Func[byte, []byte]
- func Cmp(s []byte, cmp func(l, r byte) bool) parser.Func[byte, []byte]
- func CrLf() parser.Func[byte, []byte]
- func Digit() parser.Func[byte, byte]
- func Fold(s []byte) parser.Func[byte, []byte]
- func HexDigit() parser.Func[byte, byte]
- func Letter() parser.Func[byte, byte]
- func Lower() parser.Func[byte, byte]
- func NewLine() parser.Func[byte, byte]
- func OctDigit() parser.Func[byte, byte]
- func Space() parser.Func[byte, byte]
- func Spaces() parser.Func[byte, []byte]
- func Tab() parser.Func[byte, byte]
- func Take(n int) parser.Func[byte, []byte]
- func TakeOf[T any]() parser.Func[byte, []byte]
- func TakeUntil(b ...byte) parser.Func[byte, []byte]
- func Upper() parser.Func[byte, byte]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlphaNum ¶
AlphaNum parses either an alphabet letter or digit.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.AlphaNum() fmt.Println(p([]byte("a"))) fmt.Println(p([]byte("9"))) fmt.Println(p([]byte("!"))) }
Output: 97 [] <nil> 57 [] <nil> 33 [] letter or digit, or, 2 errors occurred: * letter, satisfy, actual '0x21', unexpected * digit, satisfy, actual '0x21', unexpected
func Any ¶
Any parses any byte.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Any() fmt.Println(p([]byte("apple"))) fmt.Println(p(nil)) }
Output: 97 [112 112 108 101] <nil> 0 [] any, unexpected EOF
func Byte ¶
Byte parses a byte and succeeds if the byte is equal to `b`.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Byte(byte('!')) fmt.Println(p([]byte("!"))) fmt.Println(p([]byte("a"))) fmt.Println(p([]byte(""))) }
Output: 33 [] <nil> 97 [] byte, expected '0x21', actual '0x61', unexpected 0 [] byte, unexpected EOF
func Bytes ¶
Bytes parses the bytes `s`.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Bytes([]byte("golang")) fmt.Println(p([]byte("golang"))) fmt.Println(p([]byte("goto"))) }
Output: [103 111 108 97 110 103] [] <nil> [103 111 116] [111] bytes, cmp, expected "golang", actual "got", unexpected
func Cmp ¶
Cmp parses the bytes `s`, using `cmp` to compare each character.
Example ¶
package main import ( "fmt" "unicode" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Cmp([]byte("golang"), func(l, r byte) bool { return unicode.ToLower(rune(l)) == unicode.ToLower(rune(r)) }) fmt.Println(p([]byte("Golang"))) fmt.Println(p([]byte("goto"))) }
Output: [71 111 108 97 110 103] [] <nil> [103 111 116] [111] cmp, expected "golang", actual "got", unexpected
func CrLf ¶
CrLf parses carriage return and newline (`"\r\n"`), returning the newline character.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.CrLf() fmt.Println(p([]byte("\r\n"))) fmt.Println(p([]byte("\r"))) fmt.Println(p([]byte("\n"))) }
Output: [13 10] [] <nil> [13] [] crlf, and, unexpected EOF [10] [] crlf, and, expected '0x0d', actual '0x0a', unexpected
func Digit ¶
Digit parses a base-10 digit.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Digit() fmt.Println(p([]byte("9"))) fmt.Println(p([]byte("A"))) }
Output: 57 [] <nil> 65 [] digit, satisfy, actual '0x41', unexpected
func Fold ¶
Fold parses the bytes `s`, are equal under Unicode case-folding.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Fold([]byte("golang")) fmt.Println(p([]byte("Golang"))) fmt.Println(p([]byte("goto"))) }
Output: [71 111 108 97 110 103] [] <nil> [103 111 116] [111] bytes fold, cmp, expected "golang", actual "got", unexpected
func HexDigit ¶
HexDigit parses a hexdecimal digit with uppercase and lowercase.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.HexDigit() fmt.Println(p([]byte("7"))) fmt.Println(p([]byte("F"))) fmt.Println(p([]byte("h"))) }
Output: 55 [] <nil> 70 [] <nil> 104 [] hex digit, satisfy, actual '0x68', unexpected
func Letter ¶
Letter parses an alphabet letter.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Letter() fmt.Println(p([]byte("a"))) fmt.Println(p([]byte("A"))) fmt.Println(p([]byte("9"))) }
Output: 97 [] <nil> 65 [] <nil> 57 [] letter, satisfy, actual '0x39', unexpected
func Lower ¶
Lower parses a lowercase letter.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Lower() fmt.Println(p([]byte("a"))) fmt.Println(p([]byte("A"))) }
Output: 97 [] <nil> 65 [] lowercase letter, satisfy, actual '0x41', unexpected
func NewLine ¶
NewLine parses a newline character (`'\n'`).
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.NewLine() fmt.Println(p([]byte("\r"))) fmt.Println(p([]byte("\n"))) }
Output: 13 [] newline, expected '0x0a', actual '0x0d', unexpected 10 [] <nil>
func OctDigit ¶
OctDigit parses an octal digit.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.OctDigit() fmt.Println(p([]byte("7"))) fmt.Println(p([]byte("8"))) }
Output: 55 [] <nil> 56 [] octal digit, satisfy, actual '0x38', unexpected
func Space ¶
Space parse a single whitespace.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Space() fmt.Println(p([]byte(" "))) fmt.Println(p([]byte(" "))) fmt.Println(p([]byte("!"))) fmt.Println(p([]byte(""))) }
Output: 32 [] <nil> 32 [32] <nil> 33 [] whitespace, satisfy, actual '0x21', unexpected 0 [] whitespace, satisfy, unexpected EOF
func Spaces ¶
Spaces parse zero or more spaces.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Spaces() fmt.Println(p([]byte(" "))) fmt.Println(p([]byte(" "))) fmt.Println(p([]byte("!"))) fmt.Println(p([]byte(""))) }
Output: [32] [] <nil> [32 32] [] <nil> [] [33] <nil> [] [] <nil>
func Tab ¶
Tab parses a tab character (`'\t'`).
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Tab() fmt.Println(p([]byte("\t"))) fmt.Println(p([]byte(" "))) }
Output: 9 [] <nil> 32 [] tab, expected '0x09', actual '0x20', unexpected
func Take ¶
Take reads a bytes of length `n`.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Take(2) fmt.Println(p([]byte("let"))) fmt.Println(p([]byte("1"))) }
Output: [108 101] [116] <nil> [] [49] take, unexpected EOF
func TakeOf ¶
Take reads a bytes of length `T`.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.TakeOf[uint16]() fmt.Println(p([]byte{0x01, 0x02, 0x03, 0x04})) fmt.Println(p([]byte{0x01})) }
Output: [1 2] [3 4] <nil> [] [1] take of, take, unexpected EOF
func TakeUntil ¶
TakeUntil reads a range of 0 or more tokens until `b` is found.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.TakeUntil('\r') fmt.Println(p([]byte("To: user@example.com\r\n"))) fmt.Println(p([]byte("foobar"))) }
Output: [84 111 58 32 117 115 101 114 64 101 120 97 109 112 108 101 46 99 111 109] [13 10] <nil> [] [] take until, expected [0x0d], actual "foobar", unexpected
func Upper ¶
Upper parses an uppercase letter.
Example ¶
package main import ( "fmt" "github.com/flier/gocombine/pkg/parser/bytes" ) func main() { p := bytes.Upper() fmt.Println(p([]byte("a"))) fmt.Println(p([]byte("A"))) }
Output: 97 [] uppercase letter, satisfy, actual '0x61', unexpected 65 [] <nil>
Types ¶
This section is empty.