grepros 1.3.0
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
ExpressionTree Class Reference
Inheritance diagram for ExpressionTree:
Inheritance graph

Public Member Functions

 __init__ (self, **props)
 
 configure (self, **props)
 
 evaluate (self, tree, terminal=None, eager=())
 
 format (self, tree, terminal=None)
 
 parse (self, text, terminal=None)
 

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 552 of file search.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
**  props 
)
@param   props  class property overrides, case-insensitive, e.g. `cased=False`

Definition at line 576 of file search.py.

Member Function Documentation

◆ configure()

configure (   self,
**  props 
)
Overrides instance configuration.

@param   props  class property overrides, case-insensitive, e.g. `cased=False`

Definition at line 584 of file search.py.

◆ evaluate()

evaluate (   self,
  tree,
  terminal = None,
  eager = () 
)
Returns result of evaluating expression tree.

@param   tree      expression tree structure as given by parse()
@param   terminal  callback(value) to evaluate value nodes with, if not using value directly
@param   eager     operators where to evaluate both operands in full, despite short-circuit

Definition at line 598 of file search.py.

◆ format()

format (   self,
  tree,
  terminal = None 
)
Returns expression tree formatted as string.

@param   tree      expression tree structure as given by parse()
@param   terminal  callback(value) to format value nodes with, if not using value directly

Definition at line 620 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.

@param   terminal  callback(text) returning node value for operands, if not using plain text

Definition at line 640 of file search.py.

Member Data Documentation

◆ AND

AND
static

Definition at line 562 of file search.py.

◆ BINARIES

tuple BINARIES = (AND, OR)
static

Definition at line 567 of file search.py.

◆ CASED

bool CASED = False
static

Definition at line 564 of file search.py.

◆ ESCAPE

ESCAPE
static

Definition at line 560 of file search.py.

◆ FORMAT_TEMPLATES

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

Definition at line 572 of file search.py.

◆ IMPLICIT

IMPLICIT = AND
static

Definition at line 565 of file search.py.

◆ LBRACE

LBRACE
static

Definition at line 560 of file search.py.

◆ NOT

NOT
static

Definition at line 562 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 568 of file search.py.

◆ OR

OR
static

Definition at line 562 of file search.py.

◆ QUOTES

QUOTES
static

Definition at line 560 of file search.py.

◆ RANKS

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

Definition at line 569 of file search.py.

◆ RBRACE

RBRACE
static

Definition at line 560 of file search.py.

◆ SEPARATORS

SEPARATORS = WHITESPACE + LBRACE + RBRACE
static

Definition at line 561 of file search.py.

◆ SHORTCIRCUITS

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

Definition at line 571 of file search.py.

◆ UNARIES

tuple UNARIES = (NOT, )
static

Definition at line 566 of file search.py.

◆ VAL

VAL
static

Definition at line 562 of file search.py.

◆ VOID

VOID = None
static

Definition at line 573 of file search.py.

◆ WHITESPACE

WHITESPACE
static

Definition at line 560 of file search.py.


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