grepros 1.2.2
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
ExpressionTree Class Reference

Parses and evaluates operator expressions like "a AND (b OR NOT c)". More...

Public Member Functions

 __init__ (self, **props)
 
 configure (self, **props)
 Overrides instance configuration.
 
 evaluate (self, tree, terminal=None, eager=())
 Returns result of evaluating expression tree.
 
 format (self, tree, terminal=None)
 Returns expression tree formatted as string.
 
 parse (self, text, terminal=None)
 Returns an operator expression like "a AND (b OR NOT c)" parsed into a binary tree.
 

Static Public Attributes

 AND
 
tuple BINARIES = (AND, OR)
 
bool CASED = False
 
 ESCAPE
 
dict FORMAT_TEMPLATES = {AND: "%s and %s", OR: "%s or %s", NOT: "not %s"}
 
 IMPLICIT = AND
 
 LBRACE
 
 NOT
 
dict OPERATORS = {AND: (lambda a, b: a and b), OR: (lambda a, b: a or b), NOT: lambda a: not a}
 
 OR
 
 QUOTES
 
dict RANKS = {VAL: 1, NOT: 2, AND: 3, OR: 4}
 
 RBRACE
 
 SEPARATORS = WHITESPACE + LBRACE + RBRACE
 
dict SHORTCIRCUITS = {AND: False, OR: True}
 
tuple UNARIES = (NOT, )
 
 VAL
 
 VOID = None
 
 WHITESPACE
 

Detailed Description

Parses and evaluates operator expressions like "a AND (b OR NOT c)".

Operands can be quoted strings, '\' can be used to escape quotes within the string. Operators are case-insensitive.

Definition at line 579 of file search.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
**  props 
)
Parameters
propsclass property overrides, case-insensitive, e.g. cased=False

Definition at line 600 of file search.py.

Member Function Documentation

◆ configure()

configure (   self,
**  props 
)

Overrides instance configuration.

Parameters
propsclass property overrides, case-insensitive, e.g. cased=False

Definition at line 610 of file search.py.

◆ evaluate()

evaluate (   self,
  tree,
  terminal = None,
  eager = () 
)

Returns result of evaluating expression tree.

Parameters
treeexpression tree structure as given by parse()
terminalcallback(value) to evaluate value nodes with, if not using value directly
eageroperators where to evaluate both operands in full, despite short-circuit

Definition at line 626 of file search.py.

◆ format()

format (   self,
  tree,
  terminal = None 
)

Returns expression tree formatted as string.

Parameters
treeexpression tree structure as given by parse()
terminalcallback(value) to format value nodes with, if not using value directly

Definition at line 647 of file search.py.

◆ parse()

parse (   self,
  text,
  terminal = None 
)

Returns an operator expression like "a AND (b OR NOT c)" parsed into a binary tree.

Binary tree like ["AND", [["VAL", "a"], ["OR", [["VAL", "b"], ["NOT", [["VAL", "c"]]]]]]]. Raises on invalid expression.

Parameters
terminalcallback(text) returning node value for operands, if not using plain text

Definition at line 669 of file search.py.

Member Data Documentation

◆ AND

AND
static

Definition at line 583 of file search.py.

◆ BINARIES

tuple BINARIES = (AND, OR)
static

Definition at line 588 of file search.py.

◆ CASED

bool CASED = False
static

Definition at line 585 of file search.py.

◆ ESCAPE

ESCAPE
static

Definition at line 581 of file search.py.

◆ FORMAT_TEMPLATES

dict FORMAT_TEMPLATES = {AND: "%s and %s", OR: "%s or %s", NOT: "not %s"}
static

Definition at line 593 of file search.py.

◆ IMPLICIT

IMPLICIT = AND
static

Definition at line 586 of file search.py.

◆ LBRACE

LBRACE
static

Definition at line 581 of file search.py.

◆ NOT

NOT
static

Definition at line 583 of file search.py.

◆ OPERATORS

dict OPERATORS = {AND: (lambda a, b: a and b), OR: (lambda a, b: a or b), NOT: lambda a: not a}
static

Definition at line 589 of file search.py.

◆ OR

OR
static

Definition at line 583 of file search.py.

◆ QUOTES

QUOTES
static

Definition at line 581 of file search.py.

◆ RANKS

dict RANKS = {VAL: 1, NOT: 2, AND: 3, OR: 4}
static

Definition at line 590 of file search.py.

◆ RBRACE

RBRACE
static

Definition at line 581 of file search.py.

◆ SEPARATORS

SEPARATORS = WHITESPACE + LBRACE + RBRACE
static

Definition at line 582 of file search.py.

◆ SHORTCIRCUITS

dict SHORTCIRCUITS = {AND: False, OR: True}
static

Definition at line 592 of file search.py.

◆ UNARIES

tuple UNARIES = (NOT, )
static

Definition at line 587 of file search.py.

◆ VAL

VAL
static

Definition at line 583 of file search.py.

◆ VOID

VOID = None
static

Definition at line 594 of file search.py.

◆ WHITESPACE

WHITESPACE
static

Definition at line 581 of file search.py.


The documentation for this class was generated from the following file: