jsonpath

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: Apache-2.0 Imports: 4 Imported by: 10

Documentation

Index

Constants

View Source
const (
	DescendantWildcardSelector = iota
	DescendantDotNameSelector
	DescendantLongSelector
)
View Source
const (
	EdgeItem = "├── "
	EdgeLast = "└── "
)

Variables

View Source
var (
	ParseError = errors.New("parse error")
)

Functions

func Entry

func Entry(yaml string, jsonpath string) string

Types

type BooleanNode

type BooleanNode struct {
	Value TokenInfo // boolean value
}

BooleanNode represents a boolean literal in a JSONPath expression.

func (*BooleanNode) End

func (n *BooleanNode) End() TokenInfo

func (*BooleanNode) Pos

func (n *BooleanNode) Pos() TokenInfo

func (*BooleanNode) String

func (n *BooleanNode) String() string

type ChildSegment

type ChildSegment struct {
	SubKind       ChildSegmentSubKind
	Tokens        []TokenInfo
	InnerSelector *Selector
}

child-segment = bracketed-selection /

("."
 (wildcard-selector /
  member-name-shorthand))

func (ChildSegment) Kind

func (c ChildSegment) Kind() Kind

type ChildSegmentSubKind

type ChildSegmentSubKind int
const (
	ChildSegmentDotWildcard ChildSegmentSubKind = iota
	ChildSegmentDotMemberName
	ChildSegmentSelector
)

type ComparisonNode

type ComparisonNode struct {
	Lhs      Expr      // left-hand side expression
	Operator TokenInfo // comparison operator
	Rhs      Expr      // right-hand side expression
}

ComparisonNode represents a comparison expression in a JSONPath filter.

type CurrentNode

type CurrentNode struct {
	At TokenInfo // position of "@"
}

CurrentNode represents the current node in a JSONPath expression.

func (*CurrentNode) String

func (n *CurrentNode) String() string

type DescendantSegment

type DescendantSegment struct {
	SubKind       DescendantSegmentSubKind
	LongFormInner Segment
}

func (DescendantSegment) Kind

func (d DescendantSegment) Kind() Kind

type DescendantSegmentSubKind

type DescendantSegmentSubKind int

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr represents a JSONPath expression.

type FunctionCallNode

type FunctionCallNode struct {
	Name   TokenInfo // function name
	Lparen TokenInfo // position of "("
	Args   []Expr    // function arguments
	Rparen TokenInfo // position of ")"
}

FunctionCallNode represents a function call in a JSONPath expression.

func (*FunctionCallNode) End

func (n *FunctionCallNode) End() TokenInfo

func (*FunctionCallNode) Pos

func (n *FunctionCallNode) Pos() TokenInfo

type Kind

type Kind int
const (
	ChildSegmentKind Kind = iota
	DescendantSegmentKind
)

type Node

type Node interface {
	Kind() Kind // The Kind of the node
}

Node represents a node in the JSONPath AST.

type NullNode

type NullNode struct {
	Null TokenInfo // position of "null"
}

NullNode represents a null literal in a JSONPath expression.

func (*NullNode) End

func (n *NullNode) End() TokenInfo

func (*NullNode) Pos

func (n *NullNode) Pos() TokenInfo

func (*NullNode) String

func (n *NullNode) String() string

type NumberNode

type NumberNode struct {
	Value TokenInfo // numeric value
}

NumberNode represents a numeric literal in a JSONPath expression.

func (*NumberNode) End

func (n *NumberNode) End() TokenInfo

func (*NumberNode) Pos

func (n *NumberNode) Pos() TokenInfo

func (*NumberNode) String

func (n *NumberNode) String() string

type Parser

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

Parser represents a JSONPath parser.

func NewParser

func NewParser(tokenizer *Tokenizer) *Parser

NewParser creates a new Parser with the given tokens.

func (*Parser) Parse

func (p *Parser) Parse() error

Parse parses the JSONPath tokens and returns the root node of the AST.

jsonpath-query      = root-identifier segments

type Query

type Query struct {
	RootNode TokenInfo
	Segments []Segment
}

JSONPath expression built from segments that have been syntactically restricted in a certain way (Section 2.3.5.1)

type RootNode

type RootNode struct {
	Dollar TokenInfo // position of "$"
}

RootNode represents the root node of a JSONPath expression.

func (*RootNode) End

func (n *RootNode) End() TokenInfo

func (*RootNode) Pos

func (n *RootNode) Pos() TokenInfo

func (*RootNode) String

func (n *RootNode) String() string

type Segment

type Segment = Node

type Selector

type Selector struct {
	SubKind SelectorSubKind
}

type SelectorSubKind

type SelectorSubKind int
const (
	SelectorSubKindWildcard SelectorSubKind = iota
	SelectorSubKindName
	SelectorSubKindArraySlice
	SelectorSubKindArrayIndex
	SelectorSubKindFilter
)

type StringNode

type StringNode struct {
	Value TokenInfo // string value
}

StringNode represents a string literal in a JSONPath expression.

func (*StringNode) End

func (n *StringNode) End() TokenInfo

func (*StringNode) Pos

func (n *StringNode) Pos() TokenInfo

func (*StringNode) String

func (n *StringNode) String() string

type Token

type Token int

Token represents a lexical token in a JSONPath expression.

const (
	ILLEGAL Token = iota
	STRING_LITERAL
	NUMBER
	STRING
	BOOLEAN
	NULL
	ROOT
	CURRENT
	WILDCARD
	RECURSIVE
	UNION
	CHILD
	ARRAY_SLICE
	FILTER
	PAREN_LEFT
	PAREN_RIGHT
	BRACKET_LEFT
	BRACKET_RIGHT
	COLON
	COMMA
	TILDE
	AND
	OR
	NOT
	EQ
	NE
	GT
	GE
	LT
	LE
	MATCHES
)

The list of tokens.

func (Token) String

func (tok Token) String() string

String returns the string representation of the token.

type TokenInfo

type TokenInfo struct {
	Token   Token
	Line    int
	Column  int
	Literal string
	Len     int
}

TokenInfo represents a token and its associated information.

type Tokenizer

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

Tokenizer represents a JSONPath tokenizer.

func NewTokenizer

func NewTokenizer(input string) *Tokenizer

NewTokenizer creates a new JSONPath tokenizer for the given input string.

func (Tokenizer) ErrorString

func (t Tokenizer) ErrorString(target TokenInfo, msg string) string

When there's an error in the tokenizer, this helps represent it.

func (Tokenizer) ErrorTokenString

func (t Tokenizer) ErrorTokenString(target TokenInfo, msg string) string

When there's an error

func (*Tokenizer) Tokenize

func (t *Tokenizer) Tokenize() Tokens

Tokenize tokenizes the input string and returns a slice of TokenInfo.

type Tokens

type Tokens []TokenInfo

Tokens represents the list of tokens

func (Tokens) IsSimple

func (tok Tokens) IsSimple() bool

Jump to

Keyboard shortcuts

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