charmed

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 9 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 DecodePos

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

update the cursor

func FilterInvalidRunes

func FilterInvalidRunes() charm.State

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

func ScanQuote

func ScanQuote(match rune, escape bool, onDone func(string)) (ret charm.State)

scans until the matching quote marker is found

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 QuoteDecoder

type QuoteDecoder struct {
	strings.Builder
}

wraps a string builder to read a quoted string or heredoc.

func (*QuoteDecoder) Interpret

func (d *QuoteDecoder) Interpret() charm.State

read until an InterpretedString (") end marker is found for heredocs: pass the indentation of the starting quote

func (*QuoteDecoder) Record

func (d *QuoteDecoder) Record() charm.State

read until an RawString (`) end marker is found for heredocs: pass the indentation of the starting quote

func (*QuoteDecoder) ScanQuote

func (d *QuoteDecoder) ScanQuote(match rune, escape, allowHere bool) charm.State

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

Jump to

Keyboard shortcuts

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