charmed

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Overview

Package charmed provides common useful states for document parsing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeDouble added in v0.9.0

func DecodeDouble(out *strings.Builder) charm.State

read until a (new) double-quote (") marker is found.

func DecodePipe added in v0.9.0

func DecodePipe(out *strings.Builder) charm.State

read until a heredoc ending marker is found.

func DecodePos

func DecodePos(y, x *int) charm.State

update the cursor

func DecodeQuote added in v0.9.0

func DecodeQuote(q rune, out *strings.Builder) (ret charm.State, okay bool)

assuming q is a rune that starts a string scalar or heredoc return an appropriate decoder for decoding the rest of the string. otherwise, returns false.

func DecodeRaw added in v0.9.0

func DecodeRaw(out *strings.Builder) charm.State

read until a (new) back-tick (`) marker is found.

func DecodeSingle added in v0.9.0

func DecodeSingle(out *strings.Builder) charm.State

read until a (new) single-quote (') marker is found.

func EscapeHere added in v0.9.0

func EscapeHere(q rune) (okay bool)

func FilterInvalidRunes

func FilterInvalidRunes() charm.State

returns an state which errors on all control codes other than newlines

func KeepEnding added in v0.9.0

func KeepEnding(q rune) (okay bool)

func StringMatch

func StringMatch(str string) charm.State

returns error if failed to match, or unhandled on the rune after the matched string. the empty string will return unmatched immediately.

func UnhandledError

func UnhandledError(watch charm.State) charm.State

turns any unhandled states returned by the watched state into errors

Types

type NumParser

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

return a state which reads until the end of string, returns error if finished incorrectly

func (*NumParser) Decode

func (p *NumParser) Decode() charm.State

return a state capable of digit parsing. note: this doesn't support leading with just a "."

func (*NumParser) GetFloat

func (p *NumParser) GetFloat() (ret float64, err error)

helper to turn a string into a value

func (*NumParser) GetNumber

func (p *NumParser) GetNumber() (ret any, err error)

returns int64 or float64

func (*NumParser) String

func (*NumParser) String() string

type QuoteOptions added in v0.9.0

type QuoteOptions int

these control how inline strings are processed

const (
	AllowHere    QuoteOptions = 1 << iota
	FoldLines                 // otherwise, keep all line feeds and leading spaces.
	AllowEscapes              // otherwise, backslashes are backslashes.
)

func (QuoteOptions) Is added in v0.9.0

func (opt QuoteOptions) Is(flag QuoteOptions) bool

Jump to

Keyboard shortcuts

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