xpathparser

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2017 License: BSD-3-Clause Imports: 7 Imported by: 3

README

xpathparser

License GoDoc Go Report Card Build Status codecov.io

Package xpathparser provides lexer and parser for XPath 1.0.

This Package parses given XPath expression to expression model.

Example

An example of using this package:

expr := xpathparser.MustParse("(/a/b)[5]")
fmt.Println(expr)

This package does not evaluate xpath. For evaluating xpaths use https://github.com/santhosh-tekuri/xpath

Documentation

Overview

Package xpathparser provides lexer and parser for XPath 1.0.

This Package parses given XPath expression to expression model.

An example of using this package:

expr := xpathparser.MustParse("(/a/b)[5]")
fmt.Println(expr)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Axis

type Axis int

Axis specifies the tree relationship between the nodes selected by the location step and the context node.

const (
	Child Axis = iota
	Descendant
	Parent
	Ancestor
	FollowingSibling
	PrecedingSibling
	Following
	Preceding
	Attribute
	Namespace
	Self
	DescendantOrSelf
	AncestorOrSelf
)

Possible values for Axis.

func (Axis) String

func (a Axis) String() string

type BinaryExpr

type BinaryExpr struct {
	LHS Expr
	Op  Op
	RHS Expr
}

BinaryExpr represents a binary operation.

func (*BinaryExpr) String

func (b *BinaryExpr) String() string

type Error

type Error struct {
	Msg    string
	XPath  string
	Offset int
}

Error is the error type returned by Parse function.

It represents a syntax error in the XPath expression.

func (*Error) Error

func (e *Error) Error() string

type Expr

type Expr interface{}

An Expr is an interface holding one of the types: *LocationPath, *FilterExpr, *PathExpr, *BinaryExpr, *NegateExpr, *VarRef, *FuncCall, Number or String

func MustParse

func MustParse(xpath string) Expr

MustParse is like Parse but panics if the xpath expression has error. It simplifies safe initialization of global variables holding parsed expressions.

func Parse

func Parse(xpath string) (expr Expr, err error)

Parse parses given xpath 1.0 expression.

type FilterExpr

type FilterExpr struct {
	Expr       Expr
	Predicates []Expr
}

FilterExpr represents https://www.w3.org/TR/xpath/#NT-FilterExpr.

func (*FilterExpr) String

func (f *FilterExpr) String() string

type FuncCall

type FuncCall struct {
	Prefix string
	Local  string
	Args   []Expr
}

FuncCall represents https://www.w3.org/TR/xpath/#section-Function-Calls.

func (*FuncCall) String

func (fc *FuncCall) String() string

type LocationPath

type LocationPath struct {
	Abs   bool
	Steps []*Step
}

LocationPath represents XPath location path.

func (*LocationPath) String

func (lp *LocationPath) String() string

type NameTest

type NameTest struct {
	Prefix string
	Local  string
}

NameTest represents https://www.w3.org/TR/xpath/#NT-NameTest.

func (*NameTest) String

func (nt *NameTest) String() string

type NegateExpr

type NegateExpr struct {
	Expr Expr
}

NegateExpr represents unary operator `-`.

func (*NegateExpr) String

func (n *NegateExpr) String() string

type NodeTest

type NodeTest interface{}

A NodeTest is an interface holding one of the types: NodeType, *NameTest, or PITest.

type NodeType

type NodeType int

NodeType represents test on node type.

const (
	Comment NodeType = iota
	Text
	Node
)

Possible values for NodeType.

func (NodeType) String

func (nt NodeType) String() string

type Number

type Number float64

Number represents number literal.

func (Number) String

func (n Number) String() string

type Op

type Op int

Op represents XPath binrary operator.

const (
	EQ Op = iota
	NEQ
	LT
	LTE
	GT
	GTE
	Add
	Subtract
	Multiply
	Mod
	Div
	And
	Or
	Union
)

Possible values for Op.

func (Op) String

func (op Op) String() string

type PITest

type PITest string

PITest represents processing-instruction test.

func (PITest) String

func (pt PITest) String() string

type PathExpr

type PathExpr struct {
	Filter       Expr
	LocationPath *LocationPath
}

PathExpr represents https://www.w3.org/TR/xpath/#NT-PathExpr.

func (*PathExpr) String

func (p *PathExpr) String() string

type Step

type Step struct {
	Axis       Axis
	NodeTest   NodeTest
	Predicates []Expr
}

Step represents XPath location step.

func (*Step) String

func (s *Step) String() string

type String

type String string

String represents string literal.

func (String) String

func (s String) String() string

type VarRef

type VarRef struct {
	Prefix string
	Local  string
}

VarRef represents https://www.w3.org/TR/xpath/#NT-VariableReference.

func (*VarRef) String

func (vr *VarRef) String() string

Jump to

Keyboard shortcuts

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