diff options
| author | 2021-07-26 20:20:10 -0400 | |
|---|---|---|
| committer | 2021-07-26 22:56:48 -0400 | |
| commit | fb57305445d575f00c6ae95377b8ed7a7e38b643 (patch) | |
| tree | 9d18b140d64d8d1338266eecd44878490eb1ae2d | |
| parent | queryparse: add function to build SQL queries (diff) | |
queryparse: remove literal set
| -rw-r--r-- | queryparse.py | 28 | ||||
| -rwxr-xr-x | test/t_queryparse.py | 3 |
2 files changed, 14 insertions, 17 deletions
diff --git a/queryparse.py b/queryparse.py index 44a42dd..544e9c4 100644 --- a/queryparse.py +++ b/queryparse.py @@ -126,46 +126,45 @@ e4 ::= TAG | "[" e1 "]"; class ParseError(Exception): pass -def e4(lits, l): +def e4(l): typ,s = classify_head(l) if typ == TokType.OPEN: - pt,l = e1(lits, l[1:]) + pt,l = e1(l[1:]) typ,_ = classify_head(l) if typ != TokType.CLOSE: raise ParseError return pt,l[1:] elif typ in LitType: - lits.add((typ, s)) return Atom(typ, s), l[1:] else: raise ParseError -def e3(lits, l): +def e3(l): typ,_ = classify_head(l) if typ == TokType.NOT: - pt,l = e4(lits, l[1:]) + pt,l = e4(l[1:]) return demorgan(pt), l - return e4(lits, l) + return e4(l) -def e2(lits, l): - pt,l = e3(lits, l) +def e2(l): + pt,l = e3(l) try: while True: - pt2,l = e3(lits, l) + pt2,l = e3(l) pt = encapsulate(pt, TokType.AND) pt.push(pt2) except ParseError: pass return pt,l -def e1(lits, l): - pt,l = e2(lits, l) +def e1(l): + pt,l = e2(l) typ,_ = classify_head(l) try: while typ == TokType.OR: - pt2,l = e2(lits, l[1:]) + pt2,l = e2(l[1:]) pt = encapsulate(pt, TokType.OR) pt.push(pt2) typ,_ = classify_head(l) @@ -174,8 +173,7 @@ def e1(lits, l): return pt,l def parse(l): - lits = set() - x,l = e1(lits, l) + x,l = e1(l) if l != []: raise ParseError - return x,lits + return x diff --git a/test/t_queryparse.py b/test/t_queryparse.py index ea15c42..1c63259 100755 --- a/test/t_queryparse.py +++ b/test/t_queryparse.py @@ -33,9 +33,8 @@ def prettyprint(s): def f(x): print(x) - v,lits = queryparse.parse(x) + v = queryparse.parse(x) prettyprint(str(v)) - print(lits) _,exr = queryparse.build([], v) prettyprint(exr) print() |
