operations

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(root types.Node, path []types.PathElement, args ...any) error

func Merge added in v0.0.7

func Merge(root types.Node, path []types.PathElement, args ...any) error

func Pop added in v0.0.8

func Pop(root types.Node, path []types.PathElement, args ...any) error

func Push added in v0.0.8

func Push(root types.Node, path []types.PathElement, args ...any) error

func Set

func Set(root types.Node, path []types.PathElement, args ...any) error

Types

type Argument added in v0.0.3

type Argument struct {
	Float  *float64 `  @Float`
	Int    *int     `| @Int`
	Bool   *Boolean `| @("true" | "false")`
	Null   bool     `| @"null"`
	String *string  `| @String | @Ident`
	JSON   *JSON    `| @JSON`
}

type ArrIndexPathElement added in v0.0.8

type ArrIndexPathElement int

func (*ArrIndexPathElement) Capture added in v0.0.8

func (b *ArrIndexPathElement) Capture(values []string) error

we need to do this because lexer will return text like `[0]` as a single token because of json

type Boolean added in v0.0.3

type Boolean bool

func (*Boolean) Capture added in v0.0.3

func (b *Boolean) Capture(values []string) error

type Call added in v0.0.3

type Call struct {
	Name      string        `@Ident`
	Path      []PathElement `"(" @@+`
	Arguments []Argument    `( "," @@ )* ")"`
}

type JSON added in v0.0.3

type JSON struct {
	Val any
}

func (*JSON) Capture added in v0.0.3

func (b *JSON) Capture(values []string) error

It's unfortunate that we have parse json one more time instead of having the value in the token already

type OpInstance added in v0.0.3

type OpInstance struct {
	Op   Operation
	Name string
	Path types.PathElementSlice
	Args []any
}

func (*OpInstance) Apply added in v0.0.3

func (op *OpInstance) Apply(root types.Node) error

func (*OpInstance) String added in v0.0.3

func (op *OpInstance) String() string

type Operation added in v0.0.3

type Operation func(root types.Node, path []types.PathElement, args ...any) error

type Parser added in v0.0.3

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

func NewParser added in v0.0.3

func NewParser() *Parser

func (*Parser) Parse added in v0.0.3

func (p *Parser) Parse(s string) (*OpInstance, error)

We should be parsing things like set(field, "123") // set a string set(field, 123) // set a number set(field, { a: 1 }) // assign an object to a field set(field, "{ a: 1 }") // assign an string to a field del(field.item) // delete a field Problems: - Only double quotes are supported for strings which makes passing valid json a pain - array indexes are not supported

type PathElement added in v0.0.3

type PathElement struct {
	// potential foot gun there, I did not want to have a
	// leading dot, but I could not write a grammar rule
	// to exclude it from the first match only, hence
	// I've made it optional
	ObjectField StringPathElement   ` "."? (@String | @Ident)`
	ArrayIdx    ArrIndexPathElement ` | @JSON`
}

type StringPathElement added in v0.0.8

type StringPathElement string

func (*StringPathElement) Capture added in v0.0.8

func (b *StringPathElement) Capture(values []string) error

Directories

Path Synopsis
scanner
Package scanner provides a scanner and tokenizer for UTF-8-encoded text.
Package scanner provides a scanner and tokenizer for UTF-8-encoded text.

Jump to

Keyboard shortcuts

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