-
Notifications
You must be signed in to change notification settings - Fork 78
/
tla.py
66 lines (52 loc) · 1016 Bytes
/
tla.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pyaici.server as aici
apalache = r"""
%start tnl
%%
List
: T
| List ", " T
;
tnl: T "/\n/";
T
// integers
: "Int"
// immutable constant strings
| "Str"
// boolean
| "Bool"
// functions
| T " -> " T
// sets
| "Set" "(" T ")"
// sequences
| "Seq" "(" T ")"
// tuples
| "<<" List ">>"
// parentheses, e.g., to change associativity of functions
| "(" T ")"
// operators
| "(" List ") => " T
;
%%
"""
async def gen_and_test_grammar():
aici.log_level = 3
await aici.FixedTokens(
"""
Here's a TLA+ spec:
---- MODULE Counter ----
VARIABLE
b
q
Init == b = TRUE
Next == q = q + 1
====
Now with added types:
---- MODULE Counter ----
VARIABLE
b: """
)
await aici.gen_tokens(yacc=apalache, max_tokens=10, store_var="b")
await aici.FixedTokens(" q: ")
await aici.gen_tokens(yacc=apalache, max_tokens=10, store_var="q")
aici.test(gen_and_test_grammar())