|
grepros 1.2.2
grep for ROS bag files and live topics
|
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 | |
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.
| __init__ | ( | self, | |
| ** | props | ||
| ) |
| configure | ( | self, | |
| ** | props | ||
| ) |
| evaluate | ( | self, | |
| tree, | |||
terminal = None, |
|||
eager = () |
|||
| ) |
Returns result of evaluating expression tree.
| tree | expression tree structure as given by parse() |
| terminal | callback(value) to evaluate value nodes with, if not using value directly |
| eager | operators where to evaluate both operands in full, despite short-circuit |
| format | ( | self, | |
| tree, | |||
terminal = None |
|||
| ) |
| 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.
| terminal | callback(text) returning node value for operands, if not using plain text |
|
static |
|
static |
|
static |