filter

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

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

Go to latest
Published: Sep 30, 2021 License: MIT Imports: 5 Imported by: 0

README

SafetyCulture fork

Forking parent repo in order to remove usage of 'bson' and update to use go modules. Doing this allows us to install this module without usage of Bazaar and opening our GOVCS to bzr. Removing 'bson' removes support for REGEX filters but these are not support within our SCIM setup.

Install

go get github.com/hiyosi/filter

Usage

func main() {
	env := filter.Env{}
	s := new(filter.Scanner)
	s.Init("ham eq \"spam\"")
	statements := filter.Parse(s)
	query, err := filter.Evaluate(statements[0], env)
	if err != nil {
	        fmt.Printf("error")
	}

	fmt.Printf("%s\n", query)  // result is output as string.
 }
map[ham:spam]

As above, result data type is map[string]interface{}.

Generate parser.go from parser.go.y

$ cd filter
$ make

Implemented operators are follows

status Operator Description
eq equal
ne not equal
co contains
sw starts with
ew ends with
pr present (has value?
gt greater than
ge greater than equal
lt less than
le less than equal
and Logical and
or Logical or
not Not function
() Precedence grouping
[] Complex attribute filter grouping

result example

  • Input data
userName eq "bjensen"
name.familyName co "O'Malley"
userName sw "J"
title pr
(title pr)
meta.lastModified gt "2011-05-13T04:42:34Z"
meta.lastModified ge "2011-05-13T04:42:34Z"
meta.lastModified lt "2011-05-13T04:42:34Z"
meta.lastModified le "2011-05-13T04:42:34Z"
title pr and userType eq "Employee"
title pr or userType eq "Intern"
schemas eq "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User"
userType eq "Employee" and (emails co "example.com" or emails co "example.org")
userType eq "Employee" and ( emails co "example.com" or emails co "example.org")
userType eq "Employee" and (emails co "example.com" or emails co "example.org" )
userType eq "Employee" and ( emails co "example.com" or emails co "example.org" )
userType ne "Employee" and not ( emails co "example.com" or  emails co "example.org" )
userType eq "Employee" and ( emails.type eq "work" )
userType eq "Employee" and emails[type eq "work" and value co "@example.com"]
emails[type eq "work" and value co "@example.com"] or ims[type eq "xmpp" and value co "@foo.com"]
  • result
map[userName:bjensen]
map[name.familyName:map[$regex:{O'Malley }]]
map[userName:map[$regex:{^J }]]
map[title:map[$exists:true]]
map[title:map[$exists:true]]
map[meta.lastModified:map[$gt:2011-05-13 04:42:34 +0000 UTC]]
map[meta.lastModified:map[$gte:2011-05-13 04:42:34 +0000 UTC]]
map[meta.lastModified:map[$lt:2011-05-13 04:42:34 +0000 UTC]]
map[meta.lastModified:map[$lte:2011-05-13 04:42:34 +0000 UTC]]
map[$and:[map[title:map[$exists:true]] map[userType:Employee]]]
map[$or:[map[title:map[$exists:true]] map[userType:Intern]]]
map[schemas:urn:ietf:params:scim:schemas:extension:enterprise:2.0:User]
map[$and:[map[userType:Employee] map[$or:[map[emails:map[$regex:{example\.com }]] map[emails:map[$regex:{example\.org }]]]]]]
map[$and:[map[userType:Employee] map[$or:[map[emails:map[$regex:{example\.com }]] map[emails:map[$regex:{example\.org }]]]]]]
map[$and:[map[userType:Employee] map[$or:[map[emails:map[$regex:{example\.com }]] map[emails:map[$regex:{example\.org }]]]]]]
map[$and:[map[userType:Employee] map[$or:[map[emails:map[$regex:{example\.com }]] map[emails:map[$regex:{example\.org }]]]]]]
map[$and:[map[userType:map[$ne:Employee]] map[$or:[map[emails:map[$not:map[$regex:{example\.com }]]] map[emails:map[$not:map[$regex:{example\.org }]]]]]]]
map[$and:[map[userType:Employee] map[emails.type:work]]]
map[$and:[map[userType:Employee] map[$and:[map[emails.type:work] map[emails.value:map[$regex:{@example\.com }]]]]]]
map[$or:[map[$and:[map[emails.type:work] map[emails.value:map[$regex:{@example\.com }]]]] map[$and:[map[ims.type:xmpp] map[ims.value:map[$regex:{@foo\.com }]]]]]]

TODO

  • Specified to attribute name with full path with schema URI.( To disambiguate duplicate names between schemas)
    • e.g. filter=urn:ietf:params:scim:schemas:core:2.0:User:userName sw "J"
  • Evaluator do not use the Env{} structure.
  • Do not use panic.

Documentation

Index

Constants

View Source
const (
	EOF     = -1
	UNKNOWN = 0
)
View Source
const AND = 57362
View Source
const CO = 57355
View Source
const EQ = 57353
View Source
const EW = 57357
View Source
const FALSE = 57348
View Source
const GE = 57359
View Source
const GT = 57358
View Source
const IDENT = 57346
View Source
const LBOXP = 57367
View Source
const LE = 57361
View Source
const LPAREN = 57365
View Source
const LT = 57360
View Source
const NE = 57354
View Source
const NOT = 57364
View Source
const NULL = 57349
View Source
const NUMBER = 57351
View Source
const OR = 57363
View Source
const PR = 57352
View Source
const RBOXP = 57368
View Source
const RPAREN = 57366
View Source
const SP = 57369
View Source
const SW = 57356
View Source
const TRUE = 57347
View Source
const VALUE = 57350

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(statement Statement, env Env) (interface{}, error)

Types

type AttrStatement

type AttrStatement struct {
	Attr     Expression
	Operator string
}

type AttrValueExpression

type AttrValueExpression struct {
	Lit string
}

type BoolExpression

type BoolExpression struct {
	Lit bool
}

type CompStatement

type CompStatement struct {
	LHE      Expression
	Operator string
	RHE      Expression
}

type Env

type Env map[string]string

type Expression

type Expression interface {
	// contains filtered or unexported methods
}

type ExpressionStatement

type ExpressionStatement struct {
	Expr Expression
}

type GroupStatement

type GroupStatement struct {
	ParentAttr   Expression
	SubStatement Statement
}

type IdentifierExpression

type IdentifierExpression struct {
	Lit string
}

type Lexer

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

func (*Lexer) Error

func (l *Lexer) Error(e string)

func (*Lexer) Lex

func (l *Lexer) Lex(lval *yySymType) int

type LogStatement

type LogStatement struct {
	LHS      Statement
	Operator string
	RHS      Statement
}

type NumberExpression

type NumberExpression struct {
	Lit int
}

type ParenStatement

type ParenStatement struct {
	Operator     string
	SubStatement Statement
}

type Position

type Position struct {
	Line   int
	Column int
}

type RegexStatement

type RegexStatement struct {
	LHE      Expression
	Operator string
	Value    interface{}
}

type Scanner

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

func (*Scanner) Init

func (s *Scanner) Init(src string)

func (*Scanner) Scan

func (s *Scanner) Scan() (tok int, lit interface{}, pos Position)

type Statement

type Statement interface {
	// contains filtered or unexported methods
}

func Parse

func Parse(s *Scanner) []Statement

type Token

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

Jump to

Keyboard shortcuts

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