strparse

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

package strparse provides a string parser and utilities.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Digit1

func Digit1() parser.Parser[rune, string]

Digit1 initializes a parser that follows (0-9)+ syntax rule.

Example
package main

import (
	"fmt"

	"github.com/Drumato/peachcomb/pkg/strparse"
)

func main() {
	i := strparse.NewCompleteInput("112233abc")
	_, o, err := strparse.Digit1()(i)
	fmt.Println(o)
	fmt.Println(err)
}
Output:


112233
<nil>

func Rune

func Rune(expected rune) parser.Parser[rune, rune]

Rune initializes a parser that consumes one rune. It's just a specialized parser from combinator.Satisfy().

Example
package main

import (
	"fmt"

	"github.com/Drumato/peachcomb/pkg/strparse"
)

func main() {
	i := strparse.NewCompleteInput("abc")
	_, o, err := strparse.Rune('a')(i)
	fmt.Printf("%c\n", o)
	fmt.Println(err)
}
Output:


a
<nil>

func Tag

func Tag(tag string) parser.Parser[rune, string]

Tag initializes a parser that checks the input starts with the tag prefix.

Example
package main

import (
	"fmt"

	"github.com/Drumato/peachcomb/pkg/strparse"
)

func main() {
	i := strparse.NewCompleteInput("Drumato")
	_, o, err := strparse.Tag("Drum")(i)
	fmt.Println(o)
	fmt.Println(err)
}
Output:


Drum
<nil>

Types

type CompleteInput added in v0.3.0

type CompleteInput struct {
	// contains filtered or unexported fields
}

CompleteInput holds the whole runes.

func NewCompleteInput added in v0.3.0

func NewCompleteInput(s string) *CompleteInput

NewCompleteInput initialiizes a CompleteInput.

func (*CompleteInput) Read added in v0.3.0

func (c *CompleteInput) Read(buf []rune) (int, error)

Read implements parser.ParseInput interface.

func (*CompleteInput) Seek added in v0.3.0

func (c *CompleteInput) Seek(n int, mode parser.SeekMode) (int, error)

Seek implements parser.ParseInput interface.

type UnexpectedPrefixError

type UnexpectedPrefixError struct {
	// contains filtered or unexported fields
}

UnexpectedPrefixError notifies the prefix of the given input is unexpected.

func (*UnexpectedPrefixError) Error

func (e *UnexpectedPrefixError) Error() string

Error implements error interface.

type UnexpectedRuneError

type UnexpectedRuneError struct {
	// contains filtered or unexported fields
}

UnexpectedRuneError notifies the head of the given input is unexpected.

func (*UnexpectedRuneError) Error

func (e *UnexpectedRuneError) Error() string

Error implements error interface.

Jump to

Keyboard shortcuts

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