jparse

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 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
}

An ArrayNode represents an array of items.

func (ArrayNode) String

func (n ArrayNode) String() string

type AssignmentNode

type AssignmentNode struct {
	Name  string
	Value Node
}

An AssignmentNode represents a variable assignment.

func (AssignmentNode) String

func (n AssignmentNode) String() string

type BlockNode

type BlockNode struct {
	Exprs []Node
}

A BlockNode represents a block expression.

func (BlockNode) String

func (n BlockNode) String() string

type BooleanNode

type BooleanNode struct {
	Value bool
}

A BooleanNode represents the boolean constant true or false.

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
}

A BooleanOperatorNode represents a boolean operation.

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
}

A ComparisonOperatorNode represents a comparison operation.

func (ComparisonOperatorNode) String

func (n ComparisonOperatorNode) String() string

type ConditionalNode

type ConditionalNode struct {
	If   Node
	Then Node
	Else Node
}

A ConditionalNode represents an if-then-else expression.

func (ConditionalNode) String

func (n ConditionalNode) String() string

type DescendentNode

type DescendentNode struct{}

A DescendentNode represents the descendent operator.

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
}

A FunctionApplicationNode represents a function application operation.

func (FunctionApplicationNode) String

func (n FunctionApplicationNode) String() string

type FunctionCallNode

type FunctionCallNode struct {
	Func Node
	Args []Node
}

A FunctionCallNode represents a call to a function.

func (FunctionCallNode) String

func (n FunctionCallNode) String() string

type GroupNode

type GroupNode struct {
	Expr Node
	*ObjectNode
}

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) 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) String

func (n NameNode) String() string

type NegationNode

type NegationNode struct {
	RHS Node
}

A NegationNode represents a numeric negation operation.

func (NegationNode) String

func (n NegationNode) String() string

type Node

type Node interface {
	String() string
	// 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{}

A NullNode represents the JSON null value.

func (NullNode) String

func (NullNode) String() string

type NumberNode

type NumberNode struct {
	Value float64
}

A NumberNode represents a number literal.

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
}

A NumericOperatorNode represents a numeric operation.

func (NumericOperatorNode) String

func (n NumericOperatorNode) String() string

type ObjectNode

type ObjectNode struct {
	Pairs [][2]Node
}

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

func (ObjectNode) String

func (n ObjectNode) String() string

type ObjectTransformationNode

type ObjectTransformationNode struct {
	Pattern Node
	Updates Node
	Deletes Node
}

An ObjectTransformationNode represents the object transformation operator.

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
}

A PartialNode represents a partially applied function.

func (PartialNode) String

func (n PartialNode) String() string

type PathNode

type PathNode struct {
	Steps      []Node
	KeepArrays bool
}

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

func (PathNode) String

func (n PathNode) String() string

type PlaceholderNode

type PlaceholderNode struct{}

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

func (PlaceholderNode) String

func (PlaceholderNode) String() string

type PredicateNode

type PredicateNode struct {
	Expr    Node
	Filters []Node
}

A PredicateNode represents a predicate expression.

func (PredicateNode) String

func (n PredicateNode) String() string

type RangeNode

type RangeNode struct {
	LHS Node
	RHS Node
}

A RangeNode represents the range operator.

func (RangeNode) String

func (n RangeNode) String() string

type RegexNode

type RegexNode struct {
	Value *regexp.Regexp
}

A RegexNode represents a regular expression.

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
}

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

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
}

A StringConcatenationNode represents a string concatenation operation.

func (StringConcatenationNode) String

func (n StringConcatenationNode) String() string

type StringNode

type StringNode struct {
	Value string
}

A StringNode represents a string literal.

func (StringNode) String

func (n StringNode) String() string

type TypedLambdaNode

type TypedLambdaNode struct {
	*LambdaNode
	In  []Param
	Out []Param
}

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

func (TypedLambdaNode) String

func (n TypedLambdaNode) String() string

type VariableNode

type VariableNode struct {
	Name string
}

A VariableNode represents a JSONata variable.

func (VariableNode) String

func (n VariableNode) String() string

type WildcardNode

type WildcardNode struct{}

A WildcardNode represents the wildcard operator.

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