Documentation ¶
Overview ¶
Package lexer provides basic helpers to implement parsers
Index ¶
- Constants
- Variables
- func IsSpace(r rune) bool
- func NewIsIn(s string) func(rune) bool
- func NewIsInRunes(s ...rune) func(rune) bool
- func NewIsNot(cond func(rune) bool) func(rune) bool
- func NewIsOneOf(s ...func(rune) bool) func(rune) bool
- func Run(fn StateFn) error
- type Error
- type Position
- type Reader
- func (b *Reader) Accept(cond func(r rune) bool) bool
- func (b *Reader) AcceptAll(cond func(r rune) bool) bool
- func (b *Reader) Discard()
- func (b *Reader) Emit() string
- func (b *Reader) PeekRune() (rune, int, error)
- func (b *Reader) ReadRune() (rune, int, error)
- func (b *Reader) String() string
- func (b *Reader) UnreadRune() error
- type StateFn
Constants ¶
const ( // ReadBufferSize indicates the initial buffer size ReadBufferSize = 1 << 7 // 128B // DoublingBufferSizeLimit indicates when we stop doubling // and just add instead DoublingBufferSizeLimit = 1 << 17 // 128KiB )
Variables ¶
Functions ¶
func IsSpace ¶ added in v0.3.6
IsSpace reports whether the rune is a space character as defined by Unicode's White Space property
func NewIsIn ¶ added in v0.3.6
NewIsIn generates a rune condition checker that accepts runes contained on the provided string
func NewIsInRunes ¶ added in v0.3.7
NewIsInRunes generates a rune condition checker that accepts the runes specified
func NewIsNot ¶ added in v0.3.6
NewIsNot generates a rune condition checker that reverses the decision of the given checker.
func NewIsOneOf ¶ added in v0.3.6
NewIsOneOf generates a run condition checker that accepts runes accepted by any of the given checkers
Types ¶
type Error ¶ added in v0.3.3
Error represents a generic parsing error
type Position ¶ added in v0.3.4
Position indicates a line and column pair on a file. Counting starts at 1.
func (*Position) Add ¶ added in v0.3.9
Add adds a relative position considering potential new lines
func (Position) GoString ¶ added in v0.3.4
GoString generates a string representation of the Position for %#v usage
func (*Position) Reset ¶ added in v0.3.4
func (p *Position) Reset()
Reset places a position at (1,1)
func (*Position) StepLine ¶ added in v0.3.4
func (p *Position) StepLine()
StepLine moves position to the start of the next line
func (*Position) StepN ¶ added in v0.3.4
StepN moves the column N places forward
type Reader ¶ added in v0.3.1
type Reader struct {
// contains filtered or unexported fields
}
Reader is a RuneReader aimed at implementing text parsers
func NewReaderBytes ¶ added in v0.3.1
NewReaderBytes creates a new runes Reader using the given bytes
func NewReaderString ¶ added in v0.3.1
NewReaderString creates a new runes Reader using the given string
func (*Reader) Accept ¶ added in v0.3.5
Accept consumes a rune from the source if it meets the condition. it returns true if the condition was met and false if it wasn't.
func (*Reader) AcceptAll ¶ added in v0.3.5
AcceptAll consumes runes from the source as long as they meet the condition. it returns true if the condition was met for at least one rune, and false if it wasn't.
func (*Reader) Discard ¶ added in v0.3.1
func (b *Reader) Discard()
Discard removes from the buffer everything that has been Read
func (*Reader) Emit ¶ added in v0.3.1
Emit returns what's already being Read and discards it afterwards
func (*Reader) PeekRune ¶ added in v0.3.1
PeekRune returns information about the next rune without moving the cursor
func (*Reader) ReadRune ¶ added in v0.3.1
ReadRune reads the next rune
func (*Reader) String ¶ added in v0.3.1
String returns what's already Read but not yet emitted or discarded