Documentation
¶
Overview ¶
Package parser implements a parser for jsonpath.
Grammar taken from https://datatracker.ietf.org/doc/draft-ietf-jsonpath-base/21/
Index ¶
- Variables
- func ParseJsonLiteral(s string) (json.Token, error)
- func ParseJsonLiteralBytes(b []byte) json.Token
- type AbsSingularQuery
- type BasicExpr
- type BasicTestExpr
- type BracketNameSegment
- type BracketedSelection
- type ChildSegment
- type Comparable
- type ComparisonExpr
- type DescendantBracketedSelection
- type DescendantSegment
- type DotSelection
- type FilterQuery
- type FilterSelector
- type FunctionArgument
- type FunctionExpr
- type FunctionExprArguments
- type FunctionExprArgumentsRest
- type IndexSegment
- type Literal
- type LogicalAndExpr
- type LogicalAndRest
- type LogicalExpr
- type LogicalOrRest
- type ParenExpr
- type Query
- type RelQuery
- type RelSingularQuery
- type Segment
- type Selector
- type SelectorRest
- type SingularQuery
- type SingularQuerySegment
- type SliceSelector
- type SliceStep
- type StringLiteral
- type TestExpr
- type Token
Constants ¶
This section is empty.
Variables ¶
View Source
var TokeniseJsonPathString = grammar.SimpleTokeniser([]grammar.TokenDef{ { Ptn: `\s+`, }, { Name: "null", Ptn: `null\b`, }, { Name: "bool", Ptn: `true\b|false\b`, }, { Name: "functionname(", Ptn: `[a-z][a-z_0-9]*\(`, }, { Name: "comparisonop", Ptn: `==|!=|<=|>=|<|>`, }, { Name: "descendantmembernameshorthand", Ptn: `\.\.[a-zA-Z_\x80-\x{D7FF}\x{E000}-\x{10FFFF}][0-9a-zA-Z_\x80-\x{D7FF}\x{E000}-\x{10FFFF}]*`, }, { Name: "membernameshorthand", Ptn: `\.[a-zA-Z_\x80-\x{D7FF}\x{E000}-\x{10FFFF}][0-9a-zA-Z_\x80-\x{D7FF}\x{E000}-\x{10FFFF}]*`, }, { Name: "op", Ptn: `&&|\|\||\.\.[*[]|\.\*|[$*:?!()@[\],]`, }, { Name: "int", Ptn: `(?:0|-?[1-9][0-9]*)(?:[^.eE0-9]|$)`, Special: func(input string) string { i := 0 if input[i] == '-' { i++ } for ; i < len(input); i++ { if input[i] > '9' || input[i] < '0' { break } } return input[:i] }, }, { Name: "number", Ptn: `(?:-?0|-?[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b`, }, { Name: "doublequotedstring", Ptn: `"(?:\\[bfnrt/\\"]|\\u[0-9ABCEFabcef][0-9A-Fa-f]{3}|\\u[Dd][0-7][0-9A-Fa-f]{2}|\\u[Dd][89ABab][0-9A-Fa-f]{2}\\u[Dd][C-Fc-f][0-9A-Fa-f]{2}|[\x20-\x21\x23-\x5B\x5D-\x{D7FF}\x{E000}-\x{10FFFF}])*"`, }, { Name: "singlequotedstring", Ptn: `'(?:\\[bfnrt/\\']|\\u[0-9ABCEFabcef][0-9A-Fa-f]{3}|\\u[Dd][0-7][0-9A-Fa-f]{2}|\\u[Dd][89ABab][0-9A-Fa-f]{2}\\u[Dd][C-Fc-f][0-9A-Fa-f]{2}|[\x20-\x26\x28-\x5B\x5D-\x{D7FF}\x{E000}-\x{10FFFF}])*'`, }, })
Functions ¶
func ParseJsonLiteralBytes ¶
Types ¶
type AbsSingularQuery ¶
type AbsSingularQuery struct {
grammar.Seq
RootIdentifier Token `tok:"op,$"`
Segments []SingularQuerySegment
}
func (*AbsSingularQuery) CompileToSingularQuery ¶
func (q *AbsSingularQuery) CompileToSingularQuery() (ast.SingularQuery, error)
type BasicExpr ¶
type BasicExpr struct {
grammar.OneOf
*ParenExpr
*ComparisonExpr
*TestExpr
}
func (*BasicExpr) CompileToLogicalExpr ¶
func (e *BasicExpr) CompileToLogicalExpr() (ast.LogicalExpr, error)
type BasicTestExpr ¶
type BasicTestExpr struct {
grammar.OneOf
*FilterQuery
*FunctionExpr
}
func (*BasicTestExpr) CompileToLogicalExpr ¶
func (e *BasicTestExpr) CompileToLogicalExpr() (ast.LogicalExpr, error)
type BracketNameSegment ¶
type BracketNameSegment struct {
grammar.Seq
OpenSquareBracket Token `tok:"op,["`
NameSelector StringLiteral
CloseSquareBracket Token `tok:"op,]"`
}
func (*BracketNameSegment) CompileToSingularQuerySegment ¶
func (s *BracketNameSegment) CompileToSingularQuerySegment() (ast.SingularQuerySegment, error)
type BracketedSelection ¶
type BracketedSelection struct {
grammar.Seq
OpenSquareBracket Token `tok:"op,["`
FirstSelector Selector
SelectorRest []SelectorRest
CloseSquareBracket Token `tok:"op,]"`
}
func (*BracketedSelection) CompileToSelectors ¶
func (s *BracketedSelection) CompileToSelectors() ([]ast.Selector, error)
type ChildSegment ¶
type ChildSegment struct {
grammar.OneOf
*BracketedSelection
*DotSelection
}
func (*ChildSegment) CompileToSegment ¶
func (s *ChildSegment) CompileToSegment() (ast.Segment, error)
type Comparable ¶
type Comparable struct {
grammar.OneOf
*Literal
*SingularQuery
*FunctionExpr
}
func (*Comparable) CompileToComparable ¶
func (c *Comparable) CompileToComparable() (ast.Comparable, error)
type ComparisonExpr ¶
type ComparisonExpr struct {
grammar.Seq
Left Comparable
Op Token `tok:"comparisonop"`
Right Comparable
}
func (*ComparisonExpr) CompileToLogicalExpr ¶
func (e *ComparisonExpr) CompileToLogicalExpr() (ast.LogicalExpr, error)
type DescendantBracketedSelection ¶
type DescendantBracketedSelection struct {
grammar.Seq
OpenSquareBracket Token `tok:"op,..["`
FirstSelector Selector
SelectorRest []SelectorRest
CloseSquareBracket Token `tok:"op,]"`
}
func (*DescendantBracketedSelection) CompileToSelectors ¶
func (s *DescendantBracketedSelection) CompileToSelectors() ([]ast.Selector, error)
type DescendantSegment ¶
type DescendantSegment struct {
grammar.OneOf
*DescendantBracketedSelection
DescendantWildcardSelector *Token `tok:"op,..*"`
DescendantMemberNameShorthand *Token `tok:"descendantmembernameshorthand"`
}
func (*DescendantSegment) CompileToSegment ¶
func (s *DescendantSegment) CompileToSegment() (ast.Segment, error)
type DotSelection ¶
type DotSelection struct {
grammar.OneOf
WildcardSelector *Token `tok:"op,.*"`
MemberNameShorthand *Token `tok:"membernameshorthand"`
}
func (*DotSelection) CompileToSelectors ¶
func (s *DotSelection) CompileToSelectors() []ast.Selector
type FilterQuery ¶
func (*FilterQuery) CompileToQuery ¶
func (q *FilterQuery) CompileToQuery() (ast.Query, error)
type FilterSelector ¶
type FilterSelector struct {
grammar.Seq
FilterIdentifier Token `tok:"op,?"`
LogicalExpr
}
func (*FilterSelector) CompileToSelector ¶
func (s *FilterSelector) CompileToSelector() (ast.Selector, error)
type FunctionArgument ¶
type FunctionArgument struct {
grammar.OneOf
*Literal
*FilterQuery
*FunctionExpr
*LogicalExpr
}
func (*FunctionArgument) CompileToFunctionArgument ¶
func (a *FunctionArgument) CompileToFunctionArgument() (ast.FunctionArgument, error)
type FunctionExpr ¶
type FunctionExpr struct {
grammar.Seq
FunctionNameAndOpenBracket Token `tok:"functionname("`
Arguments *FunctionExprArguments
CloseBracket Token `tok:"op,)"`
}
func (*FunctionExpr) CompileToFunctionExpr ¶
func (e *FunctionExpr) CompileToFunctionExpr() (ast.FunctionExpr, error)
type FunctionExprArguments ¶
type FunctionExprArguments struct {
grammar.Seq
First FunctionArgument
Rest []FunctionExprArgumentsRest
}
func (*FunctionExprArguments) CompileToFunctionArguments ¶
func (a *FunctionExprArguments) CompileToFunctionArguments() ([]ast.FunctionArgument, error)
type FunctionExprArgumentsRest ¶
type FunctionExprArgumentsRest struct {
grammar.Seq
Comma Token `tok:"op,,"`
FunctionArgument
}
type IndexSegment ¶
type IndexSegment struct {
grammar.Seq
OpenSquareBracket Token `tok:"op,["`
IndexSelector Token `tok:"int"`
CloseSquareBracket Token `tok:"op,]"`
}
func (*IndexSegment) CompileToSingularQuerySegment ¶
func (s *IndexSegment) CompileToSingularQuerySegment() (ast.SingularQuerySegment, error)
type Literal ¶
type LogicalAndExpr ¶
type LogicalAndExpr struct {
grammar.Seq
First BasicExpr
Rest []LogicalAndRest
}
func (*LogicalAndExpr) CompileToLogicalExpr ¶
func (e *LogicalAndExpr) CompileToLogicalExpr() (ast.LogicalExpr, error)
type LogicalAndRest ¶
type LogicalExpr ¶
type LogicalExpr struct {
grammar.Seq
First LogicalAndExpr
Rest []LogicalOrRest
}
func (*LogicalExpr) CompileToLogicalExpr ¶
func (e *LogicalExpr) CompileToLogicalExpr() (ast.LogicalExpr, error)
type LogicalOrRest ¶
type LogicalOrRest struct {
grammar.Seq
Or Token `tok:"op,||"`
Operand LogicalAndExpr
}
type ParenExpr ¶
type ParenExpr struct {
grammar.Seq
Not *Token `tok:"op,!"`
OpenParen Token `tok:"op,("`
LogicalExpr
CloseParen Token `tok:"op,)"`
}
func (*ParenExpr) CompileToLogicalExpr ¶
func (e *ParenExpr) CompileToLogicalExpr() (ast.LogicalExpr, error)
type RelSingularQuery ¶
type RelSingularQuery struct {
grammar.Seq
CurrentNodeIdentifier Token `tok:"op,@"`
Segments []SingularQuerySegment
}
func (*RelSingularQuery) CompileToSingularQuery ¶
func (q *RelSingularQuery) CompileToSingularQuery() (ast.SingularQuery, error)
type Segment ¶
type Segment struct {
grammar.OneOf
*ChildSegment
*DescendantSegment
}
type Selector ¶
type Selector struct {
grammar.OneOf
NameSelector *StringLiteral
WildcardSelector *Token `tok:"op,*"`
*SliceSelector
IndexSelector *Token `tok:"int"`
*FilterSelector
}
type SingularQuery ¶
type SingularQuery struct {
grammar.OneOf
*RelSingularQuery
*AbsSingularQuery
}
func (*SingularQuery) CompileToSingularQuery ¶
func (q *SingularQuery) CompileToSingularQuery() (ast.SingularQuery, error)
type SingularQuerySegment ¶
type SingularQuerySegment struct {
grammar.OneOf
*BracketNameSegment
DotNameSegment *Token `tok:"membernameshorthand"`
*IndexSegment
}
func (*SingularQuerySegment) CompileToSingularQuerySegment ¶
func (s *SingularQuerySegment) CompileToSingularQuerySegment() (ast.SingularQuerySegment, error)
type SliceSelector ¶
type SliceSelector struct {
grammar.Seq
Start *Token `tok:"int"`
Colon Token `tok:"op,:"`
End *Token `tok:"int"`
*SliceStep
}
func (*SliceSelector) CompileToSelector ¶
func (s *SliceSelector) CompileToSelector() (ast.Selector, error)
type StringLiteral ¶
type StringLiteral struct {
grammar.OneOf
DoubleQuotedString *Token `tok:"doublequotedstring"`
SingleQuotedString *Token `tok:"singlequotedstring"`
}
func (*StringLiteral) CompileToString ¶
func (s *StringLiteral) CompileToString() (string, error)
type TestExpr ¶
type TestExpr struct {
grammar.Seq
Not *Token `tok:"op,!"`
BasicTestExpr
}
func (*TestExpr) CompileToLogicalExpr ¶
func (e *TestExpr) CompileToLogicalExpr() (ast.LogicalExpr, error)
type Token ¶
type Token = grammar.SimpleToken
Click to show internal directories.
Click to hide internal directories.