Documentation
¶
Overview ¶
Package runes provides parsers for recognizing runes
Index ¶
- func EscapedString() parser.Parser[parser.Reader, string]
- func One() parser.Parser[parser.Reader, rune]
- func OneOf(runes ...rune) parser.Parser[parser.Reader, rune]
- func OneOf0(runes ...rune) parser.Parser[parser.Reader, string]
- func OneOf1(runes ...rune) parser.Parser[parser.Reader, string]
- func Rune(r rune) parser.Parser[parser.Reader, rune]
- func Take(n int) parser.Parser[parser.Reader, string]
- func TakeWhile(predicate parser.Predicate[rune]) parser.Parser[parser.Reader, string]
- func TakeWhile1(predicate parser.Predicate[rune]) parser.Parser[parser.Reader, string]
- func TakeWhileMinMax(min, max int, predicate parser.Predicate[rune]) parser.Parser[parser.Reader, string]
Examples ¶
- One (EndOfFile)
- One (Match)
- OneOf (EndOfFile)
- OneOf (Match)
- OneOf (NoMatch)
- OneOf0 (EndOfFile)
- OneOf0 (Match)
- OneOf0 (NoMatch)
- OneOf1 (EndOfFile)
- OneOf1 (Match)
- OneOf1 (NoMatch)
- Rune (EndOfFile)
- Rune (Match)
- Rune (NoMatch)
- Take (EndOfFile)
- Take (Match)
- Take (UnexpectedEndOfFile)
- TakeWhile (EndOfFile)
- TakeWhile (Match)
- TakeWhile (NoMatch)
- TakeWhile1 (EndOfFile)
- TakeWhile1 (Match)
- TakeWhile1 (NoMatch)
- TakeWhileMinMax (EndOfFile)
- TakeWhileMinMax (Match)
- TakeWhileMinMax (NoMatch)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func One ¶
One reads a single rune
- If the input isn't empty, it will return a single rune.
- If the input is empty, it will return io.EOF
Example (EndOfFile) ¶
package main import ( "bytes" "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" ) func main() { input := bytes.NewReader([]byte{}) numericParser := runes.One() match, err := numericParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: %v", match, err, remainder) }
Output: Match: 0, Error: 'EOF', Remainder: []
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("𒀀𒀀") numericParser := runes.One() match, err := numericParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, remainder) }
Output: Match: '𒀀', Error: <nil>, Remainder: '𒀀'
func OneOf ¶
OneOf matches one of the argument runes
- If the input matches the argument, it will return a single matched rune.
- 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/runes" "io" "strings" ) func main() { input := strings.NewReader("") runeParser := runes.OneOf('𒀀', 'a') match, err := runeParser(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/runes" "io" "strings" ) func main() { input := strings.NewReader("𒀀a𒀀") runeParser := runes.OneOf('𒀀', 'a') match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '𒀀', Error: <nil>, Remainder: 'a𒀀'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("123") runeParser := runes.OneOf('𒀀', 'a') match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: %d, Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 0, Error: 'not matched', Remainder: '123'
func OneOf0 ¶
OneOf0 matches zero or more runes matching one of the argument runes
- If the input matches the argument, it will return a string of all matched runes.
- If the input is empty, it will return an empty string.
- If the input doesn't match, it will return an empty string.
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("") runeParser := runes.OneOf0('𒀀', 'a') match, err := runeParser(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/runes" "io" "strings" ) func main() { input := strings.NewReader("𒀀a𒀀123") runeParser := runes.OneOf0('𒀀', 'a') match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '𒀀a𒀀', Error: <nil>, Remainder: '123'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("123") runeParser := runes.OneOf0('𒀀', 'a') match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '', Error: <nil>, Remainder: '123'
func OneOf1 ¶
OneOf1 matches one or more runes matching one of the argument runes
- If the input matches the argument, it will return a string of all matched runes.
- 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/runes" "io" "strings" ) func main() { input := strings.NewReader("") runeParser := runes.OneOf1('𒀀', 'a') match, err := runeParser(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/runes" "io" "strings" ) func main() { input := strings.NewReader("𒀀a𒀀123") runeParser := runes.OneOf1('𒀀', 'a') match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '𒀀a𒀀', Error: <nil>, Remainder: '123'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("123") runeParser := runes.OneOf1('𒀀', 'a') match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", string(match), err, string(remainder)) }
Output: Match: '', Error: 'not matched', Remainder: '123'
func Rune ¶
Rune matches a single rune
The input data will be compared to the match argument.
- If the input matches the argument, 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/runes" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := runes.Rune('𒀁') 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/runes" "io" "strings" ) func main() { input := strings.NewReader("𒀀a𒀀") byteParser := runes.Rune('𒀀') 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: 'a𒀀'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("𒀀a𒀀") byteParser := runes.Rune('𒀁') 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: '𒀀a𒀀'
func Take ¶
Take returns a string containing n runes from the input
- If the input contains n runes, it will return a string.
- If the input doesn't contain n runes, it will return io.EOF.
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("") byteParser := runes.Take(4) match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '', Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("𒀀a𒀀") byteParser := runes.Take(2) match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '𒀀a', Error: <nil>, Remainder: '𒀀'
Example (UnexpectedEndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" ) func main() { input := strings.NewReader("𒀀a𒀀") byteParser := runes.Take(4) match, err := byteParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '', Error: 'EOF', Remainder: '𒀀a𒀀'
func TakeWhile ¶
TakeWhile returns a string containing zero or more Returns a string containing that match the predicate.
- If the input matches the predicate, it will return the matched runes.
- If the input is empty, it will return an empty string
- If the input doesn't match the predicate, it will return an empty string
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("") runeParser := runes.TakeWhile(unicode.IsDigit) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '', Error: <nil>, Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("abc123") runeParser := runes.TakeWhile(unicode.IsLetter) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 'abc', Error: <nil>, Remainder: '123'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("abc") runeParser := runes.TakeWhile(unicode.IsDigit) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '', Error: <nil>, Remainder: 'abc'
func TakeWhile1 ¶
TakeWhile1 returns a string containing one or more runes that match the predicate.
- If the input matches the predicate, it will return the matched runes.
- If the input is empty, it will return io.EOF
- If the input doesn't match the predicate, it will return parser.ErrNotMatched
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("") runeParser := runes.TakeWhile1(unicode.IsDigit) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '', Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("abc123") runeParser := runes.TakeWhile1(unicode.IsLetter) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 'abc', Error: <nil>, Remainder: '123'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("abc") runeParser := runes.TakeWhile1(unicode.IsDigit) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '', Error: 'not matched', Remainder: 'abc'
func TakeWhileMinMax ¶
func TakeWhileMinMax(min, max int, predicate parser.Predicate[rune]) parser.Parser[parser.Reader, string]
TakeWhileMinMax returns a string of length (m <= len <= n) containing runes that match the predicate.
- If the input matches the predicate, it will return the matched runes.
- If the input is empty and m > 0, it will return io.EOF
- If the number of matched bytes < m, it will return parser.ErrNotMatched
Example (EndOfFile) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("") runeParser := runes.TakeWhileMinMax(1, 2, unicode.IsDigit) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '', Error: 'EOF', Remainder: ''
Example (Match) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("abc") runeParser := runes.TakeWhileMinMax(1, 2, unicode.IsLetter) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: %v, Remainder: '%s'", match, err, string(remainder)) }
Output: Match: 'ab', Error: <nil>, Remainder: 'c'
Example (NoMatch) ¶
package main import ( "fmt" "github.com/roblovelock/gobble/pkg/parser/runes" "io" "strings" "unicode" ) func main() { input := strings.NewReader("abc") runeParser := runes.TakeWhileMinMax(1, 2, unicode.IsDigit) match, err := runeParser(input) remainder, _ := io.ReadAll(input) fmt.Printf("Match: '%s', Error: '%v', Remainder: '%s'", match, err, string(remainder)) }
Output: Match: '', Error: 'not matched', Remainder: 'abc'
Types ¶
This section is empty.