shortcut

package
v0.24.6 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package shortcut transforms strings into dotted paths.

Some examples:

"@var.5"
"#obj.field"
"#`i have some complex name`.field"
"@@ starts with a single at sign"
"## starts with a single hash mark"

Rules:

  • names consist of alpha numeric runes, underscores are transformed into spaces, case is ignored but lowercase is preferred.
  • paths are composed of a target and subsequent path parts.
  • targets start with either "@" for variables, or "#" for objects followed by a name.
  • path parts follow the target, begin with ".", and are either names or numbers.
  • as a special case, a name can also be enclosed in backtick or doublequotes. ( usually it will be backtick because these are embedded in json style strings, so the double quotes would have to be escaped in the original

Index

Constants

View Source
const (
	HashMark       = '#'
	AtSign         = '@'
	FieldSeparator = '.'
	RawQuote       = '`'
	DoubleQuote    = '"'
	Underscore     = '_'
	Eof            = charm.Eof
	Space          = ' '
)

Variables

View Source
var KeepShortcuts bool

should ReadDots try to keep the shortcut string ( ex. for debugging )

Functions

func Decoder

func Decoder(dec *decode.Decoder, slot *typeinfo.Slot, body any) (ret typeinfo.Instance, err error)

func Encoder

func Encoder(enc *encode.Encoder, op typeinfo.Instance) (ret any, err error)

move to a better location...

func NewTokenizer

func NewTokenizer(n Notifier) charm.State

func ReadDots

func ReadDots(str string) (ret rtti.Address, err error)

func Tokenize

func Tokenize(str string, n Notifier) error

func WriteDots

func WriteDots(a rt.Address) (ret string, okay bool)

this can only write addresses and dots composed of literals

Types

type NotShort

type NotShort int

this isnt a shortcut string the value of the error is 0 for normal strings or 1 if there is a double at or double hash ( so you can slice with this error code ]

func (NotShort) Error

func (e NotShort) Error() string

type Notifier

type Notifier interface {
	Decoded(Type, any) error
}

tbd: maybe a channel instead?

type Shortcut

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

func (*Shortcut) Decoded

func (a *Shortcut) Decoded(t Type, v any) (err error)

func (*Shortcut) Finish

func (a *Shortcut) Finish(str string) (ret rtti.Address)

type Type

type Type int
const (
	InvalidToken Type = iota
	ObjMarker         // rune
	VarMarker         // rune
	PlainName         // string
	QuotedName        // string
	Number            // number
)

func (Type) IsMarker

func (t Type) IsMarker() bool

func (Type) IsName

func (t Type) IsName() bool

func (Type) IsNumber

func (t Type) IsNumber() bool

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

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