jparse

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package jparse converts JSONata expressions to abstract syntax trees. Most clients will not need to work with this package directly.

Usage

Call the Parse function, passing a JSONata expression as a string. If an error occurs, it will be of type Error. Otherwise, Parse returns the root Node of the AST.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayNode

type ArrayNode struct {
	Items []Node
	// contains filtered or unexported fields
}

An ArrayNode represents an array of items.

func (*ArrayNode) Pos added in v1.6.6

func (n *ArrayNode) Pos() int

func (ArrayNode) String

func (n ArrayNode) String() string

type AssignmentNode

type AssignmentNode struct {
	Name  string
	Value Node
	// contains filtered or unexported fields
}

An AssignmentNode represents a variable assignment.

func (*AssignmentNode) Pos added in v1.6.6

func (n *AssignmentNode) Pos() int

func (AssignmentNode) String

func (n AssignmentNode) String() string

type BlockNode

type BlockNode struct {
	Exprs []Node
	// contains filtered or unexported fields
}

A BlockNode represents a block expression.

func (*BlockNode) Pos added in v1.6.6

func (n *BlockNode) Pos() int

func (BlockNode) String

func (n BlockNode) String() string

type BooleanNode

type BooleanNode struct {
	Value bool
	// contains filtered or unexported fields
}

A BooleanNode represents the boolean constant true or false.

func (*BooleanNode) Pos added in v1.6.6

func (n *BooleanNode) Pos() int

func (BooleanNode) String

func (n BooleanNode) String() string

type BooleanOperator

type BooleanOperator uint8

A BooleanOperator is a logical AND or OR operation between two values.

const (
	BooleanAnd BooleanOperator
	BooleanOr
)

Boolean operations supported by JSONata.

func (BooleanOperator) String

func (op BooleanOperator) String() string

type BooleanOperatorNode

type BooleanOperatorNode struct {
	Type BooleanOperator
	LHS  Node
	RHS  Node
	// contains filtered or unexported fields
}

A BooleanOperatorNode represents a boolean operation.

func (*BooleanOperatorNode) Pos added in v1.6.6

func (n *BooleanOperatorNode) Pos() int

func (BooleanOperatorNode) String

func (n BooleanOperatorNode) String() string

type ComparisonOperator

type ComparisonOperator uint8

A ComparisonOperator is an operation that compares two values.

const (
	ComparisonEqual ComparisonOperator
	ComparisonNotEqual
	ComparisonLess
	ComparisonLessEqual
	ComparisonGreater
	ComparisonGreaterEqual
	ComparisonIn
)

Comparison operations supported by JSONata.

func (ComparisonOperator) String

func (op ComparisonOperator) String() string

type ComparisonOperatorNode

type ComparisonOperatorNode struct {
	Type ComparisonOperator
	LHS  Node
	RHS  Node
	// contains filtered or unexported fields
}

A ComparisonOperatorNode represents a comparison operation.

func (*ComparisonOperatorNode) Pos added in v1.6.6

func (n *ComparisonOperatorNode) Pos() int

func (ComparisonOperatorNode) String

func (n ComparisonOperatorNode) String() string

type ConditionalNode

type ConditionalNode struct {
	If   Node
	Then Node
	Else Node
	// contains filtered or unexported fields
}

A ConditionalNode represents an if-then-else expression.

func (*ConditionalNode) Pos added in v1.6.6

func (n *ConditionalNode) Pos() int

func (ConditionalNode) String

func (n ConditionalNode) String() string

type DescendentNode

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

A DescendentNode represents the descendent operator.

func (*DescendentNode) Pos added in v1.6.6

func (n *DescendentNode) Pos() int

func (DescendentNode) String

func (DescendentNode) String() string

type ErrType

type ErrType uint

ErrType describes the type of an error.

const (
	ErrSyntaxError ErrType
	ErrUnexpectedEOF
	ErrUnexpectedToken
	ErrMissingToken
	ErrPrefix
	ErrInfix
	ErrUnterminatedString
	ErrUnterminatedRegex
	ErrUnterminatedName
	ErrIllegalEscape
	ErrIllegalEscapeHex
	ErrInvalidNumber
	ErrNumberRange
	ErrEmptyRegex
	ErrInvalidRegex
	ErrGroupPredicate
	ErrGroupGroup
	ErrPathLiteral
	ErrIllegalAssignment
	ErrIllegalParam
	ErrDuplicateParam
	ErrParamCount
	ErrInvalidUnionType
	ErrUnmatchedOption
	ErrUnmatchedSubtype
	ErrInvalidSubtype
	ErrInvalidParamType
)

Error types returned by the parser.

type Error

type Error struct {
	Type     ErrType
	Token    string
	Hint     string
	Position int
}

Error describes an error during parsing.

func (Error) Error

func (e Error) Error() string

type FunctionApplicationNode

type FunctionApplicationNode struct {
	LHS Node
	RHS Node
	// contains filtered or unexported fields
}

A FunctionApplicationNode represents a function application operation.

func (*FunctionApplicationNode) Pos added in v1.6.6

func (n *FunctionApplicationNode) Pos() int

func (FunctionApplicationNode) String

func (n FunctionApplicationNode) String() string

type FunctionCallNode

type FunctionCallNode struct {
	Func Node
	Args []Node
	// contains filtered or unexported fields
}

A FunctionCallNode represents a call to a function.

func (*FunctionCallNode) Pos added in v1.6.6

func (n *FunctionCallNode) Pos() int

func (FunctionCallNode) String

func (n FunctionCallNode) String() string

type GroupNode

type GroupNode struct {
	Expr Node
	*ObjectNode
	// contains filtered or unexported fields
}

A GroupNode represents a group expression.

func (GroupNode) String

func (n GroupNode) String() string

type LambdaNode

type LambdaNode struct {
	Body       Node
	ParamNames []string
	// contains filtered or unexported fields
}

A LambdaNode represents a user-defined JSONata function.

func (*LambdaNode) Pos added in v1.6.6

func (n *LambdaNode) Pos() int

func (LambdaNode) Shorthand

func (n LambdaNode) Shorthand() bool

Shorthand returns true if the lambda function was defined with the shorthand symbol "λ", and false otherwise. This doesn't affect evaluation but may be useful when recreating a JSONata expression from its AST.

func (LambdaNode) String

func (n LambdaNode) String() string

type NameNode

type NameNode struct {
	Value string
	// contains filtered or unexported fields
}

A NameNode represents a JSON field name.

func (NameNode) Escaped

func (n NameNode) Escaped() bool

Escaped returns true for names enclosed in backticks (e.g. `Product Name`), and false otherwise. This doesn't affect evaluation but may be useful when recreating a JSONata expression from its AST.

func (*NameNode) Pos added in v1.6.6

func (n *NameNode) Pos() int

func (NameNode) String

func (n NameNode) String() string

type NegationNode

type NegationNode struct {
	RHS Node
	// contains filtered or unexported fields
}

A NegationNode represents a numeric negation operation.

func (*NegationNode) Pos added in v1.6.6

func (n *NegationNode) Pos() int

func (NegationNode) String

func (n NegationNode) String() string

type Node

type Node interface {
	String() string

	Pos() int
	// contains filtered or unexported methods
}

Node represents an individual node in a syntax tree.

func Parse

func Parse(expr string) (root Node, err error)

Parse builds the abstract syntax tree for a JSONata expression and returns the root node. If the provided expression is not valid, Parse returns an error of type Error.

type NullNode

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

A NullNode represents the JSON null value.

func (*NullNode) Pos added in v1.6.6

func (n *NullNode) Pos() int

func (NullNode) String

func (NullNode) String() string

type NumberNode

type NumberNode struct {
	Value float64
	// contains filtered or unexported fields
}

A NumberNode represents a number literal.

func (*NumberNode) Pos added in v1.6.6

func (n *NumberNode) Pos() int

func (NumberNode) String

func (n NumberNode) String() string

type NumericOperator

type NumericOperator uint8

A NumericOperator is a mathematical operation between two numeric values.

const (
	NumericAdd NumericOperator
	NumericSubtract
	NumericMultiply
	NumericDivide
	NumericModulo
)

Numeric operations supported by JSONata.

func (NumericOperator) String

func (op NumericOperator) String() string

type NumericOperatorNode

type NumericOperatorNode struct {
	Type NumericOperator
	LHS  Node
	RHS  Node
	// contains filtered or unexported fields
}

A NumericOperatorNode represents a numeric operation.

func (*NumericOperatorNode) Pos added in v1.6.6

func (n *NumericOperatorNode) Pos() int

func (NumericOperatorNode) String

func (n NumericOperatorNode) String() string

type ObjectNode

type ObjectNode struct {
	Pairs [][2]Node
	// contains filtered or unexported fields
}

An ObjectNode represents an object, an unordered list of key-value pairs.

func (*ObjectNode) Pos added in v1.6.6

func (n *ObjectNode) Pos() int

func (ObjectNode) String

func (n ObjectNode) String() string

type ObjectTransformationNode

type ObjectTransformationNode struct {
	Pattern Node
	Updates Node
	Deletes Node
	// contains filtered or unexported fields
}

An ObjectTransformationNode represents the object transformation operator.

func (*ObjectTransformationNode) Pos added in v1.6.6

func (n *ObjectTransformationNode) Pos() int

func (ObjectTransformationNode) String

func (n ObjectTransformationNode) String() string

type Param

type Param struct {
	Type      ParamType
	Option    ParamOpt
	SubParams []Param
}

A Param represents a parameter in a lambda function signature.

func (Param) String

func (p Param) String() string

type ParamOpt

type ParamOpt uint8

A ParamOpt represents the options on a parameter in a lambda function signature.

const (

	// ParamOptional denotes an optional parameter.
	ParamOptional ParamOpt

	// ParamVariadic denotes a variadic parameter.
	ParamVariadic

	// ParamContextable denotes a parameter that can be
	// replaced by the evaluation context if no value is
	// provided by the caller.
	ParamContextable
)

func (ParamOpt) String

func (opt ParamOpt) String() string

type ParamType

type ParamType uint

A ParamType represents the type of a parameter in a lambda function signature.

const (
	ParamTypeNumber ParamType = 1 << iota
	ParamTypeString
	ParamTypeBool
	ParamTypeNull
	ParamTypeArray
	ParamTypeObject
	ParamTypeFunc
	ParamTypeJSON
	ParamTypeAny
)

Supported parameter types.

func (ParamType) String

func (typ ParamType) String() string

type PartialNode

type PartialNode struct {
	Func Node
	Args []Node
	// contains filtered or unexported fields
}

A PartialNode represents a partially applied function.

func (*PartialNode) Pos added in v1.6.6

func (n *PartialNode) Pos() int

func (PartialNode) String

func (n PartialNode) String() string

type PathNode

type PathNode struct {
	Steps      []Node
	KeepArrays bool
	// contains filtered or unexported fields
}

A PathNode represents a JSON object path. It consists of one or more 'steps' or Nodes (most commonly NameNode objects).

func (*PathNode) Pos added in v1.6.6

func (n *PathNode) Pos() int

func (PathNode) String

func (n PathNode) String() string

type PlaceholderNode

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

A PlaceholderNode represents a placeholder argument in a partially applied function.

func (*PlaceholderNode) Pos added in v1.6.6

func (n *PlaceholderNode) Pos() int

func (PlaceholderNode) String

func (PlaceholderNode) String() string

type PredicateNode

type PredicateNode struct {
	Expr    Node
	Filters []Node
	// contains filtered or unexported fields
}

A PredicateNode represents a predicate expression.

func (*PredicateNode) Pos added in v1.6.6

func (n *PredicateNode) Pos() int

func (PredicateNode) String

func (n PredicateNode) String() string

type RangeNode

type RangeNode struct {
	LHS Node
	RHS Node
	// contains filtered or unexported fields
}

A RangeNode represents the range operator.

func (*RangeNode) Pos added in v1.6.6

func (n *RangeNode) Pos() int

func (RangeNode) String

func (n RangeNode) String() string

type RegexNode

type RegexNode struct {
	Value *regexp.Regexp
	// contains filtered or unexported fields
}

A RegexNode represents a regular expression.

func (*RegexNode) Pos added in v1.6.6

func (n *RegexNode) Pos() int

func (RegexNode) String

func (n RegexNode) String() string

type SortDir

type SortDir uint8

SortDir describes the sort order of a sort operation.

const (
	SortDefault SortDir
	SortAscending
	SortDescending
)

Sort orders supported by JSONata.

type SortNode

type SortNode struct {
	Expr  Node
	Terms []SortTerm
	// contains filtered or unexported fields
}

A SortNode represents a sort clause on a JSONata path step.

func (*SortNode) Pos added in v1.6.6

func (n *SortNode) Pos() int

func (SortNode) String

func (n SortNode) String() string

type SortTerm

type SortTerm struct {
	Dir  SortDir
	Expr Node
}

A SortTerm defines a JSONata sort term.

type StringConcatenationNode

type StringConcatenationNode struct {
	LHS Node
	RHS Node
	// contains filtered or unexported fields
}

A StringConcatenationNode represents a string concatenation operation.

func (*StringConcatenationNode) Pos added in v1.6.6

func (n *StringConcatenationNode) Pos() int

func (StringConcatenationNode) String

func (n StringConcatenationNode) String() string

type StringNode

type StringNode struct {
	Value string
	// contains filtered or unexported fields
}

A StringNode represents a string literal.

func (*StringNode) Pos added in v1.6.6

func (n *StringNode) Pos() int

func (StringNode) String

func (n StringNode) String() string

type TypedLambdaNode

type TypedLambdaNode struct {
	*LambdaNode
	In  []Param
	Out []Param
	// contains filtered or unexported fields
}

A TypedLambdaNode represents a user-defined JSONata function with a type signature.

func (*TypedLambdaNode) Pos added in v1.6.6

func (n *TypedLambdaNode) Pos() int

func (TypedLambdaNode) String

func (n TypedLambdaNode) String() string

type VariableNode

type VariableNode struct {
	Name string
	// contains filtered or unexported fields
}

A VariableNode represents a JSONata variable.

func (*VariableNode) Pos added in v1.6.6

func (n *VariableNode) Pos() int

func (VariableNode) String

func (n VariableNode) String() string

type WildcardNode

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

A WildcardNode represents the wildcard operator.

func (*WildcardNode) Pos added in v1.6.6

func (n *WildcardNode) Pos() int

func (WildcardNode) String

func (WildcardNode) String() string

Jump to

Keyboard shortcuts

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