ascii

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ascii provides parsers for recognizing ascii bytes

Index

Examples

Constants

This section is empty.

Variables

View Source
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

func Digit() parser.Parser[parser.Reader, byte]

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

func Digit0() parser.Parser[parser.Reader, []byte]

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

func Digit1() parser.Parser[parser.Reader, []byte]

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 Float32

func Float32() parser.Parser[parser.Reader, float32]

Float32 will parse a number in text form to float32

func Float64

func Float64() parser.Parser[parser.Reader, float64]

Float64 will parse a number in text form to float64

func Int16

func Int16() parser.Parser[parser.Reader, 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

func Int32() parser.Parser[parser.Reader, 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

func Int64() parser.Parser[parser.Reader, 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

func Int8() parser.Parser[parser.Reader, 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 IsASCII

func IsASCII(val byte) bool

IsASCII Tests if input is an ASCII character: 0x00-0x7F

func IsAlphanumeric

func IsAlphanumeric(val byte) bool

IsAlphanumeric Tests if input is ASCII alphanumeric: A-Z, a-z, 0-9

func IsDigit

func IsDigit(val byte) bool

IsDigit Tests if input is ASCII digit: 0-9

func IsHexDigit

func IsHexDigit(val byte) bool

IsHexDigit Tests if input is ASCII hex digit: 0-9, A-F, a-f

func IsLetter

func IsLetter(val byte) bool

IsLetter Tests if input is ASCII letter: A-Z, a-z

func IsOctDigit

func IsOctDigit(val byte) bool

IsOctDigit Tests if input is ASCII octal digit: 0-7

func SkipWhitespace

func SkipWhitespace() parser.Parser[parser.Reader, parser.Empty]

func SkipWhitespace0

func SkipWhitespace0() parser.Parser[parser.Reader, parser.Empty]

func SkipWhitespace1

func SkipWhitespace1() parser.Parser[parser.Reader, parser.Empty]

func UInt16

func UInt16() parser.Parser[parser.Reader, 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

func UInt32() parser.Parser[parser.Reader, 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

func UInt64() parser.Parser[parser.Reader, 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

func UInt8() parser.Parser[parser.Reader, 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'

func Whitespace

func Whitespace() parser.Parser[parser.Reader, byte]

func Whitespace0

func Whitespace0() parser.Parser[parser.Reader, []byte]

func Whitespace1

func Whitespace1() parser.Parser[parser.Reader, []byte]

Types

This section is empty.

Jump to

Keyboard shortcuts

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