expr

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

This package implements compilers for SCIM path and SCIM filters, and defines the basic data structure for their representation in memory.

Index

Constants

View Source
const (
	LeftParen  = "("
	RightParen = ")"
	And        = "and"
	Or         = "or"
	Not        = "not"
	Eq         = "eq"
	Ne         = "ne"
	Sw         = "sw"
	Ew         = "ew"
	Co         = "co"
	Pr         = "pr"
	Gt         = "gt"
	Ge         = "ge"
	Lt         = "lt"
	Le         = "le"
)

Keyword and operators

Variables

This section is empty.

Functions

func RegisterURN

func RegisterURN(urn string)

RegisterURN saves the given urn into the lookup structure, so it could be referenced later. This is necessary because the URN prefix defined in SCIM breaks ordinary path syntax by the use of dot (.). Normally, dot is used to separate path segments (i.e. name.familyName). However, dot is also contained in URN prefix such as

urn:ietf:params:scim:schemas:core:2.0:User

to indicate version 2.0. Hence, the compiler needs to recognize these URN prefixes in advance to properly parse them as a path segment instead of delimiting by dot.

Types

type Expression

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

Expression is the basic data structure that composes SCIM filters and SCIM paths. It doubles as a node in a single linked list when acting as a segment in SCIM paths, and a node in a binary tree when acting as a token in SCIM filters.

func CompileFilter

func CompileFilter(filter string) (*Expression, error)

CompileFilter compiles the given SCIM filter and return the root of the abstract syntax tree, or any error.

For example, for a filter such as:

(value eq "foo") and (primary ne true)

CompileFilter will return an abstract syntax tree in the structure of:

          and
        /    \
     eq        \
    /  \         \
value  "foo"     ne
                /  \
           primary true

func CompilePath

func CompilePath(path string) (*Expression, error)

CompilePath compiles the given SCIM path expression and returns the head of the path expression linked list, or any error. The result may contain a filter root node, depending on the given path expression.

For example, for a path such as:

name.familyName

CompilePath returns a structure like:

name -> familyName

For a path such as:

emails[value eq "foo@bar.com"].primary

CompilePath returns a structure like:

emails -> eq -> primary
         /  \
      value  "foo@bar.com"

func (*Expression) ContainsFilter

func (e *Expression) ContainsFilter() bool

ContainsFilter returns true if the remaining of the path whose first node is represented by this expression contains a filter.

func (*Expression) IsLeftParenthesis

func (e *Expression) IsLeftParenthesis() bool

IsLeftParenthesis returns true if this Expression is a left parenthesis

func (*Expression) IsLiteral

func (e *Expression) IsLiteral() bool

IsLiteral returns true if this Expression represents a literal.

func (*Expression) IsLogicalOperator

func (e *Expression) IsLogicalOperator() bool

IsLogicalOperator returns true if this Expression holds a SCIM logical filter operator.

func (*Expression) IsOperator

func (e *Expression) IsOperator() bool

IsOperator returns true if this Expression holds a SCIM filter operator (either logical or relational).

func (*Expression) IsParenthesis

func (e *Expression) IsParenthesis() bool

IsParenthesis returns true if this Expression is a parenthesis

func (*Expression) IsPath

func (e *Expression) IsPath() bool

IsPath returns tree if this Expression represents a segment of a SCIM path.

func (*Expression) IsRelationalOperator

func (e *Expression) IsRelationalOperator() bool

IsRelationalOperator returns true if this Expression holds a SCIM relational filter operator.

func (*Expression) IsRightParenthesis

func (e *Expression) IsRightParenthesis() bool

IsRightParenthesis returns true if this Expression is a right parenthesis

func (*Expression) IsRootOfFilter

func (e *Expression) IsRootOfFilter() bool

IsRootOfFilter returns true if this Expression, while being on the linked list, is also an operator. This indicates that this Expression is the root of a filter tree. This method only does a simple test and shall only be called while traversing the linked list.

func (*Expression) Left

func (e *Expression) Left() *Expression

Left returns the left child in the tree, or nil if this Expression does not have left child.

func (*Expression) Next

func (e *Expression) Next() *Expression

Next returns the next Expression in the linked list, or nil if this Expression is the tail.

func (*Expression) Right

func (e *Expression) Right() *Expression

Right returns the right child in the tree, or nil if this Expression does not have right child.

func (*Expression) Token

func (e *Expression) Token() string

Token returns the string representation of this Expression.

func (*Expression) Walk

func (e *Expression) Walk(cb func(expression *Expression), marker *Expression, done func())

Walk traverses the hybrid linked list / tree structure connected to the current step. cb is the callback function invoked for each step; marker and done comprises the termination mechanism. When the current step finishes its traversal, it compares itself against marker. If they are equal, invoke the done function to let the caller know we have returned to the node that the Walk function is initially invoked on, hence the traversal has ended.

Jump to

Keyboard shortcuts

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