probably.util
¶
- probably.util.dedup_list(data)[source]¶
Deduplicate a list using a set, preserving the ordering of the list.
>>> dedup_list([1,2,3,3]) [1, 2, 3]
Mutable References¶
- class probably.util.ref.Mut(read, write)[source]¶
A mutable reference to a value of type M, represented a getter and a setter. Use
val
to read and write the value.Mut is useful to transform an AST while walking it.
- property val: M¶
Property that wraps
read
andwrite
.
- static list(values)[source]¶
Create a Mut for each element in the list.
>>> my_list = [1, 2, 3] >>> ref_list = list(Mut.list(my_list)) >>> ref_list[0].val = 15 >>> my_list [15, 2, 3]
- static dict_items(values)[source]¶
Create a Mut for each key-value pair in the dict.
>>> my_dict = {'hello': 42} >>> refs = list(Mut.dict_items(my_dict)) >>> refs[0][1].val = 43 >>> my_dict {'hello': 43}
- static dict_values(values)[source]¶
A Mut reference to each value in the map. See
dict_items()
.
Lark Expression Parser¶
Generate Lark grammars for expressions from operator tables. The algorithm is pretty simple, but easy to mess up when doing it by hand.
>>> table = [
... [infixl("plus", "+"), infixl("minus", "-")],
... [prefix("neg", "-"), atom("parens", '"(" test ")"'), atom("int", "/[0-9]+/")]
... ]
>>> print(build_expr_parser(table, "test"))
?test: test_0
?test_0: test_1
| test_0 "+" test_1 -> plus
| test_0 "-" test_1 -> minus
?test_1: "-" test_1 -> neg
| "(" test ")" -> parens
| /[0-9]+/ -> int
- class probably.util.lark_expr_parser.Assoc(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
- LEFT = 1¶
- RIGHT = 2¶