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
|
#!/usr/bin/python3
import sys
sys.path.insert(0, "../")
import queryparse
def prettyprint(s):
ind = 0
start = True
for i in s:
if i == "\n":
if not start:
print(" ", end="")
start = True
continue
if (i == " " or i == "\t") and start:
continue
start = False
if i == "(":
ind = ind + 1
print()
for j in range(0,ind):
print(" ", end="")
start = False
print("(", end="")
elif i == ")":
print(")")
ind = ind - 1
for j in range(0, ind):
print(" ", end="")
start = True
else:
print(i, end="")
def f(x):
print(x)
v = queryparse.parse(x)
prettyprint(str(v))
_,exr = queryparse.build([], v)
prettyprint(exr)
print()
f(["x", "OR", "y"])
f(["x", "y", "OR", "x", "b"])
f(["x", "y", "z", "w"])
f(["NOT", "x", "OR", "y"])
f(["NOT", "[", "x", "y", "z", "]"])
f(["x", "y", "NOT", "z", "[", "a", "OR", "b", "]", "c"])
f(["x", "y", "z", "OR", "NOT", "x", "a", "z"])
f(["~~internal-*", "~-Application*", "NOT", "~~*xyz*"])
f(["NOT", "[", "x", "y", "z", "OR", "x", "a", "]", "b"])
|