hup.base.parser module¶
Multi-Purpose Expression Parser.
-
class
Expression
(tokens: List[hup.base.parser.Token], vocabulary: hup.base.parser.Vocabulary, mapping: Optional[dict] = None)¶ Bases:
object
-
as_func
(compile: bool = True) → Callable¶
-
as_string
(translate: Optional[dict] = None) → str¶
-
eval
(*args, **kwds) → Any¶
-
origin
¶
-
simplify
(values: Optional[dict] = None) → hup.base.parser.Expression¶
-
subst
(key: str, expr: Union[Expression, str]) → hup.base.parser.Expression¶ Substitute variable in expression.
-
symbols
¶
-
variables
¶
-
-
class
Parser
(vocabulary: Optional[hup.base.parser.Vocabulary] = None)¶ Bases:
object
-
eval
(expression: str, *args, **kwds) → Any¶
-
expression
¶
-
parse
(expression: str, variables: Optional[Tuple[str, ...]] = None) → hup.base.parser.Expression¶
-
success
¶
-
-
class
PyBuiltin
¶ Bases:
hup.base.parser.PyOperators
Python3 Operators and Builtins.
-
class
PyOperators
¶ Bases:
hup.base.parser.Vocabulary
Python3 Operators.
This vocabulary is based on https://docs.python.org/3/reference/expressions.html
Hint
In difference to standard Python interpreter, some expressions are not valid: Invalid: x + -y -> Valid: x + (-y)
-
class
Symbol
(type: int, key: str, value: Any, priority: int = 0, builtin: bool = False, factory: bool = False)¶ Bases:
object
Data Class for Parser Symbols.
-
builtin
= False¶
-
factory
= False¶
-
priority
= 0¶
-
-
class
Token
(type: int, id: Union[str, int] = 0, priority: int = 0, value: Any = 0, key: str = '')¶ Bases:
object
-
id
= 0¶
-
key
= ''¶
-
priority
= 0¶
-
value
= 0¶
-
-
class
Vocabulary
¶ Bases:
set
Base Class for Parser Vocabularies.
-
get
(type: int, key: str) → hup.base.parser.Symbol¶ Get symbol from vocabulary.
-
search
(type: Optional[int] = None, builtin: Optional[bool] = None) → Dict[str, hup.base.parser.Symbol]¶ Search for symbols within the vocabulary.
Parameters: - type – Integer parameter representing the type of symbols.
- builtin – Optional Boolean parameter representing the ‘builtin’ flag of the symbols. For ‘True’, only symbols are returned, that are marked to be builtin symbols, for ‘False’ only symbols, that are marked not to be builtin. By default the ‘builtin’ flag is ignored in the search result.
Returns: OrderedDict containing Symbols in reverse lexical order to prioritize symbols with greater lenght.
-
-
pack
(a: Any, b: Any) → hup.base.parser._Pack¶ Pack Arguments together.
-
parse
(expression: str, variables: Optional[Tuple[str, ...]] = None, vocabulary: Optional[hup.base.parser.Vocabulary] = None) → hup.base.parser.Expression¶