parser

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: 1 Imported by: 0

Documentation

Overview

package parser provides abstract interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorIs

func ErrorIs[T ParseError](err error, ty T) bool

ErrorIs checks the given error implements ParseError interface.

Types

type IOReadSeeker added in v0.3.0

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

IOReadSeeker is the stream input. We should require io.Seeker because some parsers try to recover from failures.

func NewIOReadSeeker added in v0.3.0

func NewIOReadSeeker(r io.ReadSeeker) *IOReadSeeker

NewIOReadSeeker initializes an IOReadSeeker.

func (*IOReadSeeker) Read added in v0.3.0

func (r *IOReadSeeker) Read(buf []byte) (int, error)

Read implements ParseInput interface.

func (*IOReadSeeker) Seek added in v0.3.0

func (r *IOReadSeeker) Seek(n int, mode SeekMode) (int, error)

Seek implements ParseInput interface.

type NoLeftInputToParseError

type NoLeftInputToParseError struct{}

NoLeftInputToParseError notifies the given input to parser is empty.

func (*NoLeftInputToParseError) Error

func (e *NoLeftInputToParseError) Error() string

Error implements error interface.

type ParseError

type ParseError interface {
	error
}

ParseError represents the error of parsers in all parsers.

type ParseInput

type ParseInput[E comparable] interface {
	// Read reads len(slice) and returns the length that the parser could read.
	Read([]E) (int, error)
	// Seek conditions the offset of the input.
	Seek(int, SeekMode) (int, error)
}

ParseInput is the input of Parser interface.

type ParseOutput

type ParseOutput interface{}

ParseOutput is the actual type of the parser's output. Note that this interface may be constrainted more in future.

type Parser

type Parser[E comparable, O ParseOutput] func(input ParseInput[E]) (ParseInput[E], O, ParseError)

Parser is an abstract parser.

type SeekMode added in v0.3.0

type SeekMode int

SeekMode specifies the behavior of Seek() method. It's similar to io.SeekMode.

const (
	// SeekModeStart indicates the Seek() method seeks from the start of the input.
	SeekModeStart SeekMode = io.SeekStart
	// SeekModeCurrent indicates the Seek() method seeks from the current offset of the input.
	SeekModeCurrent SeekMode = io.SeekCurrent
)

Jump to

Keyboard shortcuts

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