filter

package module
v0.0.0-...-b33ea97 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 8 Imported by: 0

README

Go Report Card GoDoc

Query Filter Parser for SCIM v2.0

links: [scim] [filtering]
other: [pratt parser] [json]

Implemented Operators

Attribute Operators
  • eq, ne, co, sw, ew, gt, ge, lt, le
  • pr
Logical Operators
  • and, or
  • not
  • precedence
Grouping Operators
  • ( )
  • [ ]

Case Sensitivity

Attribute names and attribute operators used in filters are case insensitive.
For example, the following two expressions will evaluate to the same logical value:

filter=userName Eq "john"
filter=Username eq "john"

Expressions Requirements

Each expression MUST contain an attribute name followed by an attribute operator and optional value.

Multiple expressions MAY be combined using logical operators.

Expressions MAY be grouped together using round brackets "(" and ")".

Filters MUST be evaluated using the following order of operations, in order of precedence:

1.  Grouping operators
2.  Attribute operators
3.  Logical operators - where "not" takes precedence over "and",
    which takes precedence over "or"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttrName

func AttrName(s string) bool

AttrName = ALPHA *(nameChar)

Types

type AttributeExpression

type AttributeExpression struct {
	Expression
	AttributePath   AttributePath
	CompareOperator Token
	CompareValue    string
}

AttributeExpression is an Expression with a name, operator and value.

func (AttributeExpression) String

func (expression AttributeExpression) String() string

type AttributePath

type AttributePath struct {
	AttributeName string
	SubAttribute  string
}

func (AttributePath) String

func (attributePath AttributePath) String() string

type BinaryExpression

type BinaryExpression struct {
	Expression
	X               Expression
	CompareOperator Token
	Y               Expression
}

BinaryExpression is an Expression with a token bound to two (child) expressions X and Y.

func (BinaryExpression) String

func (expression BinaryExpression) String() string

type Expression

type Expression interface{}

Expression is a type to assign to implemented expressions.

type Parser

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

Parser is a parser.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser.

func (*Parser) Parse

func (parser *Parser) Parse() (Expression, error)

Parse returns an abstract syntax tree of the string in the scanner. https://tools.ietf.org/html/rfc7644#section-3.4.2.2

func (*Parser) ParsePath

func (parser *Parser) ParsePath() (Path, error)

ParsePath parses the "path" attribute value in the scanner. RFC: https://tools.ietf.org/html/rfc7644#section-3.5.2

type Path

type Path struct {
	AttributeName   string
	SubAttribute    string
	ValueExpression Expression
}

func (Path) String

func (path Path) String() string

type Scanner

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

Scanner is a lexical scanner.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

func (scanner *Scanner) Scan() (Token, string)

Scan returns the next token and literal value.

type Token

type Token int

Token is an int type representing tokens.

const (
	// UNKNOWN is an unknown token
	UNKNOWN Token = iota

	// WHITESPACE is a whitespace (i.e. " ")
	WHITESPACE
	// IDENTIFIER is an identifier (i.e. "userName")
	IDENTIFIER
	// EOF represents an end-of-file
	EOF
	// VALUE is a value (i.e. "john")
	VALUE

	// EQ = equals
	EQ
	// NE = not equal
	NE
	// CO = contains
	CO
	// SW = starts with
	SW
	// EW = ends with
	EW
	// PR = present (has value)
	PR
	// GT = greater than
	GT
	// GE = greater than or equal to
	GE
	// LT = less than
	LT
	// LE = less than or equal to
	LE

	// AND = logical "and"
	AND
	// OR = logical "or"
	OR
	// NOT = "not" function
	NOT

	// LeftParenthesis = "("
	LeftParenthesis
	// RightParenthesis = ")"
	RightParenthesis
	// LeftBracket = "["
	LeftBracket
	// RightBracket = "]"
	RightBracket

	// Dot = .
	Dot
)

func (Token) IsAssociative

func (token Token) IsAssociative() bool

IsAssociative return whether the token in associative.

func (Token) IsOperator

func (token Token) IsOperator() bool

IsOperator returns whether the token is an operator.

func (Token) Precedence

func (token Token) Precedence() int

Precedence returns the precedence value of the token.

func (Token) String

func (token Token) String() string

type UnaryExpression

type UnaryExpression struct {
	Expression
	CompareOperator Token
	X               Expression
}

UnaryExpression is an Expression with a token bound to a (child) expression X.

func (UnaryExpression) String

func (expression UnaryExpression) String() string

type ValuePath

type ValuePath struct {
	Expression
	AttributeName   string
	ValueExpression Expression
}

func (ValuePath) String

func (valuePath ValuePath) String() string

Jump to

Keyboard shortcuts

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