Documentation ¶
Index ¶
- func CheckAllFunctionsWereTested() error
- func GetProgListing(prog Prog, level int) string
- func GetSubExpr(expr string, preds int) (retStr string)
- func NewCtxFromCurrent(goctx gocontext.Context, mach *Machine, current Entry) *context
- func NewCtxFromMach(mach *Machine, ctxNode xutils.XpathNode) *context
- func RegisterCustomFunctions(customFunctionInfoTbl []CustomFunctionInfo)
- func SetDebugLogger(logger *log.Logger)
- func TypeIsBool(d Datum) (bool, string)
- func TypeIsDatumSlice(d Datum) (bool, string)
- func TypeIsLiteral(d Datum) (bool, string)
- func TypeIsNodeset(d Datum) (bool, string)
- func TypeIsNumber(d Datum) (bool, string)
- func TypeIsObject(d Datum) (bool, string)
- type CommonLex
- func (lexer *CommonLex) AllowCustomFns() *CommonLex
- func (x *CommonLex) ConstructToken(c rune, tokenMatcher tokenMatcherFn, tokenName string) bytes.Buffer
- func (lexer *CommonLex) CreateProgram(expr string) (prog []Inst, err error)
- func (x *CommonLex) Error(s string)
- func (lexer *CommonLex) GetError() error
- func (lexer *CommonLex) GetLine() []byte
- func (lexer *CommonLex) GetMapFn() PfxMapFn
- func (lexer *CommonLex) GetProgBldr() *ProgBuilder
- func (x *CommonLex) IsNameChar(c rune) bool
- func (x *CommonLex) IsNameStartChar(c rune) bool
- func (x *CommonLex) LexAsterisk() (int, TokVal)
- func (x *CommonLex) LexColon() (int, TokVal)
- func (x *CommonLex) LexDot(c rune) (int, TokVal)
- func (x *CommonLex) LexLiteral(quote rune) (int, TokVal)
- func (x *CommonLex) LexName(c rune) (int, TokVal)
- func (x *CommonLex) LexNum(c rune) (int, TokVal)
- func (x *CommonLex) LexPunctuation(c rune) (int, TokVal)
- func (x *CommonLex) LexRelationalOperator(c rune) (int, TokVal)
- func (x *CommonLex) LexSlash() (int, TokVal)
- func (x *CommonLex) Next() rune
- func (x *CommonLex) NextNonWhitespace() rune
- func (x *CommonLex) NextNonWhitespaceStringIs(expr string) bool
- func (lexer *CommonLex) Parse()
- func (x *CommonLex) SaveTokenType(tokenType int)
- func (lexer *CommonLex) SetError(err error)
- func (lexer *CommonLex) SetUserFnChecker(userFnChecker UserCustomFunctionCheckerFn)
- type CustomFn
- type CustomFunctionInfo
- type Datum
- type DatumTypeChecker
- type Entry
- type Inst
- type Machine
- type PathStack
- type PfxMapFn
- type PredicatePathElemStack
- type Prog
- type ProgBuilder
- func (progBldr *ProgBuilder) Add(ctx *context)
- func (progBldr *ProgBuilder) And(ctx *context)
- func (progBldr *ProgBuilder) CodeBltin(sym *Symbol, numArgs int)
- func (progBldr *ProgBuilder) CodeEvalLocPathExists()
- func (progBldr *ProgBuilder) CodeFn(fn instFunc, fnName string)
- func (progBldr *ProgBuilder) CodeLiteral(lit string)
- func (progBldr *ProgBuilder) CodeNameTest(name xml.Name)
- func (progBldr *ProgBuilder) CodeNum(num float64)
- func (progBldr *ProgBuilder) CodePathOper(elem int)
- func (progBldr *ProgBuilder) CodePathSetCurrent()
- func (progBldr *ProgBuilder) CodePredEnd()
- func (progBldr *ProgBuilder) CodePredEndIgnore()
- func (progBldr *ProgBuilder) CodePredStart()
- func (progBldr *ProgBuilder) CodePredStartIgnore()
- func (progBldr *ProgBuilder) CodeSubMachine(fn instFunc, fnName, subMachine string)
- func (progBldr *ProgBuilder) Deref()
- func (progBldr *ProgBuilder) Div(ctx *context)
- func (progBldr *ProgBuilder) Eq(ctx *context)
- func (progBldr *ProgBuilder) EvalLocPath(ctx *context)
- func (progBldr *ProgBuilder) EvalLocPathExists(ctx *context)
- func (progBldr *ProgBuilder) EvalLocPathInternal(ctx *context)
- func (progBldr *ProgBuilder) FilterExprEnd(ctx *context)
- func (progBldr *ProgBuilder) Ge(ctx *context)
- func (progBldr *ProgBuilder) GetMainProg() (prog Prog, err error)
- func (progBldr *ProgBuilder) Gt(ctx *context)
- func (progBldr *ProgBuilder) LRefEquals(ctx *context)
- func (progBldr *ProgBuilder) LRefPredEnd(ctx *context)
- func (progBldr *ProgBuilder) Le(ctx *context)
- func (progBldr *ProgBuilder) Lt(ctx *context)
- func (progBldr *ProgBuilder) Mod(ctx *context)
- func (progBldr *ProgBuilder) Mul(ctx *context)
- func (progBldr *ProgBuilder) Ne(ctx *context)
- func (progBldr *ProgBuilder) Negate(ctx *context)
- func (progBldr *ProgBuilder) NewPathStackFromActual() instFunc
- func (progBldr *ProgBuilder) Or(ctx *context)
- func (progBldr *ProgBuilder) PredicatesEnd()
- func (progBldr *ProgBuilder) PredicatesStart()
- func (progBldr *ProgBuilder) PushBool(b bool)
- func (progBldr *ProgBuilder) PushNotFound()
- func (progBldr *ProgBuilder) Store(ctx *context)
- func (progBldr *ProgBuilder) StorePathEval(ctx *context)
- func (progBldr *ProgBuilder) Sub(ctx *context)
- func (progBldr *ProgBuilder) Text()
- func (progBldr *ProgBuilder) Union(ctx *context)
- func (progBldr *ProgBuilder) UnsupportedName(tokenType int, token string)
- type ProgStack
- type Result
- func (res *Result) GetBoolResult() (bool, error)
- func (res *Result) GetDebugOutput() string
- func (res *Result) GetError() error
- func (res *Result) GetLiteralResult() (string, error)
- func (res *Result) GetNodeSetResult() ([]xutils.XpathNode, error)
- func (res *Result) GetNonWarnings() []xutils.Warning
- func (res *Result) GetNumResult() (float64, error)
- func (res *Result) GetWarnings() []xutils.Warning
- func (res *Result) IsNumber() bool
- func (res *Result) PrintResult() string
- type Symbol
- func LookupXpathFunction(name string, customFnsAllowed bool, userFnCheckFn UserCustomFunctionCheckerFn) (*Symbol, bool)
- func NewCustomFnSym(name string, fn CustomFn, argTypeCheckers []DatumTypeChecker, ...) *Symbol
- func NewDummyFnSym(name string) *Symbol
- func NewFnSym(name string, fn bltinFn, argTypeCheckers []DatumTypeChecker, ...) *Symbol
- type TokVal
- type UserCustomFunctionCheckerFn
- type XpathLexer
- type XpathPlugin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAllFunctionsWereTested ¶
func CheckAllFunctionsWereTested() error
func GetProgListing ¶
func GetSubExpr ¶
Extract relevant predicate from expression - 'preds' indicates which '[' is the starting point.
func NewCtxFromCurrent ¶
func NewCtxFromMach ¶
NewCtxFromMach - return new context in which to run instance of machine.
Use for creating context for top-level machine - machines for nested predicates etc need fine-tuning.
func RegisterCustomFunctions ¶
func RegisterCustomFunctions(customFunctionInfoTbl []CustomFunctionInfo)
func SetDebugLogger ¶
func TypeIsBool ¶
func TypeIsDatumSlice ¶ added in v0.0.8
func TypeIsLiteral ¶
func TypeIsNodeset ¶
func TypeIsNumber ¶
func TypeIsObject ¶
Allow for invalidDatum here hence default case.
Types ¶
type CommonLex ¶
type CommonLex struct {
// contains filtered or unexported fields
}
COMMONLEX
func NewCommonLex ¶
func NewCommonLex( line []byte, progBldr *ProgBuilder, mapFn PfxMapFn, ) CommonLex
func (*CommonLex) AllowCustomFns ¶
func (*CommonLex) ConstructToken ¶
func (x *CommonLex) ConstructToken( c rune, tokenMatcher tokenMatcherFn, tokenName string, ) bytes.Buffer
Given first character in token and function to identify further elements, return full token and set x.peek to the correct character.
func (*CommonLex) CreateProgram ¶
func (*CommonLex) Error ¶
The parser calls this method on a parse error. It stores the error in the machine for later retrieval.
func (*CommonLex) GetProgBldr ¶
func (lexer *CommonLex) GetProgBldr() *ProgBuilder
func (*CommonLex) IsNameChar ¶
func (*CommonLex) IsNameStartChar ¶
func (*CommonLex) LexAsterisk ¶
func (*CommonLex) LexLiteral ¶
Lex 'literal' string contained in single or double quotes
func (*CommonLex) LexName ¶
Lex a non-literal name (ie something textual that isn't quoted).
Rules for disambiguating:
(a) If there is a preceding token, and said token is none of '@', '::',
'(', '[', ',' or an Operator, then '*' is the MultiplyOperator and NCName must be recognised as an OperatorName
(b) If the character following an NCName (possibly after intervening
whitespace) is '(', then the token must be recognized as a NodeType or FunctionName
(c) If an NCName is followed by '::' (possibly with intervening whitespace)
then the NCName must be recognised as an AxisName
(d) In all other cases, the token must NOT be recognised as a Multiply
Operator, OperatorName, NodeType, FunctionName, or AxisName
func (*CommonLex) LexPunctuation ¶
Separated out to allow us to override it.
func (*CommonLex) LexRelationalOperator ¶
func (*CommonLex) Next ¶
Return the next rune for the lexer. 'peek' may have been set if we needed to look ahead but then didn't consume the character. In other words, what remains to be parsed when we call Next() is:
x.peek (if not EOF) + x.line
func (*CommonLex) NextNonWhitespace ¶
func (*CommonLex) NextNonWhitespaceStringIs ¶
Won't handle string containing whitespace. For now we only need this to match '(', '::', ':' and '*'. This assumes the passed in string consists of ASCII bytes
func (*CommonLex) SaveTokenType ¶
Some parsing will produce different tokens depending on what came before so we need to keep track of this.
func (*CommonLex) SetUserFnChecker ¶
func (lexer *CommonLex) SetUserFnChecker( userFnChecker UserCustomFunctionCheckerFn, )
type CustomFunctionInfo ¶
type CustomFunctionInfo struct { // Function name as used in XPATH must statement. Lower case and hyphen // are only allowed characters. Name string // Implementation of the function. FnPtr CustomFn // Arguments (type and number) taken by the function Args []DatumTypeChecker // Return value type RetType DatumTypeChecker // Default return value, for use if function panics for any reason. DefaultRetVal Datum }
Plugins need to provide a table, exported as 'RegistrationData', which is a slice of the following structure.
type Datum ¶
type Datum interface { // Return datum value as the type requested, if possible. All 4 // base types (bool, literal, number, nodeset) may be converted // to bool / literal / number. Only a nodeset datum can take // nodeset form - you cannot convert to it. // // 'context' is a string that is added to the panic error message if // the conversion fails for any reason. Boolean(context string) bool Literal(context string) string Nodeset(context string) []xutils.XpathNode Number(context string) float64 DatumSlice(context string) []Datum // contains filtered or unexported methods }
func NewBoolDatum ¶
func NewDatumSliceDatum ¶ added in v0.0.8
func NewInvalidDatum ¶
func NewInvalidDatum() Datum
func NewLiteralDatum ¶
func NewNodesetDatum ¶
func NewNumDatum ¶
type DatumTypeChecker ¶
For type checking the likes of return values for built-in functions. string provides a name to identify the type that has or hasn't been matched. Purely for debug
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
func NewMachineWithLocation ¶
func (*Machine) AllowedValues ¶
Wrapper around a machine that will return the set of values. If empty, must return []string{} not nil or TmplGetAllowed will barf with the likes of 'wrong return type for TmplGetAllowed got <nil> expecting []string'.
func (*Machine) GetLocation ¶
func (*Machine) PrintMachine ¶
Useful for debugging machines when they don't quite work as expected!
type PathStack ¶ added in v0.0.6
type PathStack struct {
// contains filtered or unexported fields
}
func (*PathStack) NewPathFromActual ¶ added in v0.0.8
func (p *PathStack) NewPathFromActual()
func (*PathStack) NewPathFromCurrent ¶ added in v0.0.6
func (p *PathStack) NewPathFromCurrent()
type PfxMapFn ¶
MACHINE
Object used to encapsulate execution of an expression. Ideally all functions above would be methods on machine, but until / unless we can get Go's YACC implementation to allow parameters to be passed into exprParse, it's hard and we have to rely on a single machine running at one time then store the results out of the parser into the machine.
type PredicatePathElemStack ¶ added in v0.0.8
type PredicatePathElemStack struct {
// contains filtered or unexported fields
}
func (*PredicatePathElemStack) AddEmptyMap ¶ added in v0.0.8
func (p *PredicatePathElemStack) AddEmptyMap()
AddEmptyMap adds a new empty map to the stack
func (*PredicatePathElemStack) PopMap ¶ added in v0.0.8
func (p *PredicatePathElemStack) PopMap() map[string]string
PopMap pops the top most path and returns it
func (*PredicatePathElemStack) TopSet ¶ added in v0.0.8
func (p *PredicatePathElemStack) TopSet(key string, value string)
TopSet adds the given key: value to the top most map
type ProgBuilder ¶
type ProgBuilder struct {
// contains filtered or unexported fields
}
PROGBUILDER
func NewProgBuilder ¶
func NewProgBuilder(refExpr string) *ProgBuilder
func (*ProgBuilder) Add ¶
func (progBldr *ProgBuilder) Add(ctx *context)
func (*ProgBuilder) And ¶
func (progBldr *ProgBuilder) And(ctx *context)
func (*ProgBuilder) CodeBltin ¶
func (progBldr *ProgBuilder) CodeBltin(sym *Symbol, numArgs int)
func (*ProgBuilder) CodeEvalLocPathExists ¶
func (progBldr *ProgBuilder) CodeEvalLocPathExists()
func (*ProgBuilder) CodeFn ¶
func (progBldr *ProgBuilder) CodeFn(fn instFunc, fnName string)
func (*ProgBuilder) CodeLiteral ¶
func (progBldr *ProgBuilder) CodeLiteral(lit string)
func (*ProgBuilder) CodeNameTest ¶
func (progBldr *ProgBuilder) CodeNameTest(name xml.Name)
func (*ProgBuilder) CodeNum ¶
func (progBldr *ProgBuilder) CodeNum(num float64)
func (*ProgBuilder) CodePathOper ¶
func (progBldr *ProgBuilder) CodePathOper(elem int)
func (*ProgBuilder) CodePathSetCurrent ¶ added in v0.0.8
func (progBldr *ProgBuilder) CodePathSetCurrent()
func (*ProgBuilder) CodePredEnd ¶
func (progBldr *ProgBuilder) CodePredEnd()
Code:
- encapsulate current program in 'parent' as EvalSubMachine() function
- remove this program from stack so next instruction goes on parent machine.
Run:
- EvalSubMachine()
func (*ProgBuilder) CodePredEndIgnore ¶
func (progBldr *ProgBuilder) CodePredEndIgnore()
func (*ProgBuilder) CodePredStart ¶
func (progBldr *ProgBuilder) CodePredStart()
Code:
- encode EvalLocPath
- start new (child) program
func (*ProgBuilder) CodePredStartIgnore ¶
func (progBldr *ProgBuilder) CodePredStartIgnore()
func (*ProgBuilder) CodeSubMachine ¶
func (progBldr *ProgBuilder) CodeSubMachine( fn instFunc, fnName, subMachine string, )
func (*ProgBuilder) Deref ¶ added in v0.0.9
func (progBldr *ProgBuilder) Deref()
func (*ProgBuilder) Div ¶
func (progBldr *ProgBuilder) Div(ctx *context)
func (*ProgBuilder) Eq ¶
func (progBldr *ProgBuilder) Eq(ctx *context)
func (*ProgBuilder) EvalLocPath ¶
func (progBldr *ProgBuilder) EvalLocPath(ctx *context)
EvalLocPath is put on the stack whenever a path is finally defined, such that the value is to be resolved and put onto the stack for other functions to evaluate.
func (*ProgBuilder) EvalLocPathExists ¶
func (progBldr *ProgBuilder) EvalLocPathExists(ctx *context)
func (*ProgBuilder) EvalLocPathInternal ¶ added in v0.0.8
func (progBldr *ProgBuilder) EvalLocPathInternal(ctx *context)
func (*ProgBuilder) FilterExprEnd ¶
func (progBldr *ProgBuilder) FilterExprEnd(ctx *context)
When we reach the end of a filter expression, we need to check that the result pushed to the stack is a nodeset (it's an error according to the XPATH RFC if not). Once checked, we push it back on the stack and increment stackedNodesets so subsequent path construction operations take this nodeset into account.
func (*ProgBuilder) Ge ¶
func (progBldr *ProgBuilder) Ge(ctx *context)
func (*ProgBuilder) GetMainProg ¶
func (progBldr *ProgBuilder) GetMainProg() (prog Prog, err error)
func (*ProgBuilder) Gt ¶
func (progBldr *ProgBuilder) Gt(ctx *context)
func (*ProgBuilder) LRefEquals ¶
func (progBldr *ProgBuilder) LRefEquals(ctx *context)
func (*ProgBuilder) LRefPredEnd ¶
func (progBldr *ProgBuilder) LRefPredEnd(ctx *context)
func (*ProgBuilder) Le ¶
func (progBldr *ProgBuilder) Le(ctx *context)
func (*ProgBuilder) Lt ¶
func (progBldr *ProgBuilder) Lt(ctx *context)
func (*ProgBuilder) Mod ¶
func (progBldr *ProgBuilder) Mod(ctx *context)
func (*ProgBuilder) Mul ¶
func (progBldr *ProgBuilder) Mul(ctx *context)
func (*ProgBuilder) Ne ¶
func (progBldr *ProgBuilder) Ne(ctx *context)
func (*ProgBuilder) Negate ¶
func (progBldr *ProgBuilder) Negate(ctx *context)
func (*ProgBuilder) NewPathStackFromActual ¶
func (progBldr *ProgBuilder) NewPathStackFromActual() instFunc
func (*ProgBuilder) Or ¶
func (progBldr *ProgBuilder) Or(ctx *context)
func (*ProgBuilder) PredicatesEnd ¶ added in v0.0.8
func (progBldr *ProgBuilder) PredicatesEnd()
func (*ProgBuilder) PredicatesStart ¶ added in v0.0.8
func (progBldr *ProgBuilder) PredicatesStart()
func (*ProgBuilder) PushBool ¶
func (progBldr *ProgBuilder) PushBool(b bool)
func (*ProgBuilder) PushNotFound ¶
func (progBldr *ProgBuilder) PushNotFound()
func (*ProgBuilder) Store ¶
func (progBldr *ProgBuilder) Store(ctx *context)
func (*ProgBuilder) StorePathEval ¶
func (progBldr *ProgBuilder) StorePathEval(ctx *context)
Unless we have one or more invalid paths (false on stack) then all is ok.
func (*ProgBuilder) Sub ¶
func (progBldr *ProgBuilder) Sub(ctx *context)
func (*ProgBuilder) Text ¶ added in v0.0.8
func (progBldr *ProgBuilder) Text()
func (*ProgBuilder) Union ¶
func (progBldr *ProgBuilder) Union(ctx *context)
func (*ProgBuilder) UnsupportedName ¶
func (progBldr *ProgBuilder) UnsupportedName(tokenType int, token string)
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
RESULT
Wrapper around the raw result of the XPath expression, so we can keep it in its native type, but convert on request to other types.
func (*Result) GetBoolResult ¶
func (*Result) GetDebugOutput ¶
func (*Result) GetLiteralResult ¶
func (*Result) GetNonWarnings ¶
func (*Result) GetNumResult ¶
func (*Result) GetWarnings ¶
func (*Result) PrintResult ¶
type Symbol ¶
type Symbol struct {
// contains filtered or unexported fields
}
func LookupXpathFunction ¶
func LookupXpathFunction( name string, customFnsAllowed bool, userFnCheckFn UserCustomFunctionCheckerFn, ) (*Symbol, bool)
LookupXpathFunction - return Symbol if 'name' is found in symbol table
Core XPATH functions are in the function table with sym.custom = false. Custom XPATH functions available in the ISO via plugins (with corresponding INI file describing them) are also in the table, with sym.custom = true.
Additionally there are circumstances (eg DRAM) where we wish to temporarily add function names to the table to prevent erroneous compiler errors. This is done via the optional userFnCheckFn which will return a dummy symbol if needed.
func NewCustomFnSym ¶
func NewCustomFnSym( name string, fn CustomFn, argTypeCheckers []DatumTypeChecker, retTypeChecker DatumTypeChecker, ) *Symbol
func NewDummyFnSym ¶
func NewFnSym ¶
func NewFnSym( name string, fn bltinFn, argTypeCheckers []DatumTypeChecker, retTypeChecker DatumTypeChecker, ) *Symbol
type TokVal ¶
type TokVal interface{}
func LexCommon ¶
func LexCommon(x XpathLexer) (tokType int, tokVal TokVal)
The parser calls this method to get each new token.
We store the token value so it is available as the preceding token value when parsing the next token.
type XpathLexer ¶
type XpathLexer interface { GetError() error SetError(err error) GetProgBldr() *ProgBuilder GetLine() []byte Parse() Next() rune SaveTokenType(tokenType int) IsNameChar(c rune) bool IsNameStartChar(c rune) bool MapTokenValToCommon(tokenType int) int LexLiteral(quote rune) (int, TokVal) LexDot(c rune) (int, TokVal) LexNum(c rune) (int, TokVal) LexSlash() (int, TokVal) LexColon() (int, TokVal) LexAsterisk() (int, TokVal) LexRelationalOperator(c rune) (int, TokVal) LexName(c rune) (int, TokVal) LexPunctuation(c rune) (int, TokVal) }
Allow for different grammars to be compiled and run using Machine, sharing common lexing code where possible.