Documentation ¶
Overview ¶
Package ascii provides parsers for recognizing ascii bytes
Index ¶
- Variables
- func Digit() parser.Parser[parser.Reader, byte]
- func Digit0() parser.Parser[parser.Reader, []byte]
- func Digit1() parser.Parser[parser.Reader, []byte]
- func Float32() parser.Parser[parser.Reader, float32]
- func Float64() parser.Parser[parser.Reader, float64]
- func Int16() parser.Parser[parser.Reader, int16]
- func Int32() parser.Parser[parser.Reader, int32]
- func Int64() parser.Parser[parser.Reader, int64]
- func Int8() parser.Parser[parser.Reader, int8]
- func IsASCII(val byte) bool
- func IsAlphanumeric(val byte) bool
- func IsDigit(val byte) bool
- func IsHexDigit(val byte) bool
- func IsLetter(val byte) bool
- func IsOctDigit(val byte) bool
- func SkipWhitespace() parser.Parser[parser.Reader, parser.Empty]
- func SkipWhitespace0() parser.Parser[parser.Reader, parser.Empty]
- func SkipWhitespace1() parser.Parser[parser.Reader, parser.Empty]
- func UInt16() parser.Parser[parser.Reader, uint16]
- func UInt32() parser.Parser[parser.Reader, uint32]
- func UInt64() parser.Parser[parser.Reader, uint64]
- func UInt8() parser.Parser[parser.Reader, uint8]
- func Whitespace() parser.Parser[parser.Reader, byte]
- func Whitespace0() parser.Parser[parser.Reader, []byte]
- func Whitespace1() parser.Parser[parser.Reader, []byte]
Examples ¶
- Digit (EndOfFile)
- Digit (Match)
- Digit (NoMatch)
- Digit0 (EndOfFile)
- Digit0 (Match)
- Digit0 (NoMatch)
- Digit1 (EndOfFile)
- Digit1 (Match)
- Digit1 (NoMatch)
- Int16 (EndOfFile)
- Int16 (Match)
- Int16 (NoMatch)
- Int16 (Overflow)
- Int32 (EndOfFile)
- Int32 (Match)
- Int32 (NoMatch)
- Int32 (Overflow)
- Int64 (EndOfFile)
- Int64 (Match)
- Int64 (NoMatch)
- Int64 (Overflow)
- Int8 (EndOfFile)
- Int8 (Match)
- Int8 (NoMatch)
- Int8 (Overflow)
- UInt16 (EndOfFile)
- UInt16 (Match)
- UInt16 (NoMatch)
- UInt16 (Overflow)
- UInt32 (EndOfFile)
- UInt32 (Match)
- UInt32 (NoMatch)
- UInt32 (Overflow)
- UInt64 (EndOfFile)
- UInt64 (Match)
- UInt64 (NoMatch)
- UInt64 (Overflow)
- UInt8 (EndOfFile)
- UInt8 (Match)
- UInt8 (NoMatch)
- UInt8 (Overflow)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOverflow the parsed digits don't fit in the value type ErrOverflow = errors.New("overflow") // the parsed digits don't fit in the value type )
Functions ¶
func Digit ¶
Digit matches a single ASCII numerical characters: 0-9
- If the input matches a numerical character, it will return the match.
- If the input is empty, it will return io.EOF
- If the input doesn't match the argument, it will return parser.ErrNotMatched
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.Digit() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123") byteParser := ascii.Digit() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '1', Error: <nil>, Remainder: '23'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.Digit() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
func Digit0 ¶
Digit0 matches zero or more ASCII numerical character: 0-9
- If the input matches a numerical character, it will return a slice of all matched digits.
- If the input is empty, it will return an empty slice.
- If the input doesn't match a numerical character, it will return an empty slice.
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.Digit0() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '', Error: <nil>, Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.Digit0() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '123', Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.Digit0() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '', Error: <nil>, Remainder: 'abc'
func Digit1 ¶
Digit1 matches one or more ASCII numerical characters: 0-9
- If the input matches a numerical character, it will return a slice of all matched digits.
- If the input is empty, it will return io.EOF.
- If the input doesn't match a numerical character, it will return parser.ErrNotMatched.
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.Digit1() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '', Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.Digit1() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '123', Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.Digit1() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '', Error: 'not matched', Remainder: 'abc'
func Int16 ¶
Int16 will parse a number in text form to int16
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.Int16() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.Int16() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 123, Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.Int16() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
Example (Overflow) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("65536a") byteParser := ascii.Int16() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'overflow', Remainder: '65536a'
func Int32 ¶
Int32 will parse a number in text form to uint32
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.Int32() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.Int32() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 123, Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.Int32() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
Example (Overflow) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("42949672950") byteParser := ascii.Int32() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'overflow', Remainder: '42949672950'
func Int64 ¶
Int64 will parse a number in text form to int64
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.Int64() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.Int64() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 123, Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.Int64() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
Example (Overflow) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("18446744073709551616") byteParser := ascii.Int64() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'overflow', Remainder: '18446744073709551616'
func Int8 ¶
Int8 will parse a number in text form to uint8
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.Int8() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.Int8() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 123, Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.Int8() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
Example (Overflow) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("1234a") byteParser := ascii.Int8() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'overflow', Remainder: '1234a'
func IsAlphanumeric ¶
IsAlphanumeric Tests if input is ASCII alphanumeric: A-Z, a-z, 0-9
func IsHexDigit ¶
IsHexDigit Tests if input is ASCII hex digit: 0-9, A-F, a-f
func IsOctDigit ¶
IsOctDigit Tests if input is ASCII octal digit: 0-7
func UInt16 ¶
UInt16 will parse a number in text form to uint16
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.UInt16() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.UInt16() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 123, Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.UInt16() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
Example (Overflow) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("65536a") byteParser := ascii.UInt16() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'overflow', Remainder: '65536a'
func UInt32 ¶
UInt32 will parse a number in text form to uint32
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.UInt32() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.UInt32() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 123, Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.UInt32() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
Example (Overflow) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("42949672950") byteParser := ascii.UInt32() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'overflow', Remainder: '42949672950'
func UInt64 ¶
UInt64 will parse a number in text form to uint64
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.UInt64() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.UInt64() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 123, Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.UInt64() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
Example (Overflow) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("18446744073709551616") byteParser := ascii.UInt64() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'overflow', Remainder: '18446744073709551616'
func UInt8 ¶
UInt8 will parse a number in text form to uint8
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := ascii.UInt8() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("123abc") byteParser := ascii.UInt8() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 123, Error: <nil>, Remainder: 'abc'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("abc") byteParser := ascii.UInt8() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: 'abc'
Example (Overflow) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/ascii" "io" "strings" ) func main() { input := strings.NewReader("1234a") byteParser := ascii.UInt8() match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'overflow', Remainder: '1234a'
Types ¶
This section is empty.