#!/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"])