diff options
| author | 2021-07-26 00:07:02 -0400 | |
|---|---|---|
| committer | 2021-07-26 22:55:52 -0400 | |
| commit | 00cb58762ca824c3dc17e9d39e0cf04c5a9e7a40 (patch) | |
| tree | 35c165b40d90e4891449b63bb4e235af20b37219 | |
| parent | queryparse: fix infinite recursion in '[' e1 ']' (diff) | |
queryparse: fix tagglob and titleglob, fix encapsulating literals
| -rw-r--r-- | queryparse.py | 19 | ||||
| -rwxr-xr-x | test/t_queryparse.py | 2 |
2 files changed, 12 insertions, 9 deletions
diff --git a/queryparse.py b/queryparse.py index 5daf702..94d1451 100644 --- a/queryparse.py +++ b/queryparse.py @@ -1,16 +1,17 @@ from enum import Enum +class LitType(Enum): + TAGGLOB = 2 + TITLEGLOB = 3 + TAG = 9 + class TokType(Enum): OR = 0 NOT = 1 - TAGGLOB = 2 - TITLEGLOB = 3 - TAGLIT = 4 EOF = 5 AND = 6 OPEN = 7 CLOSE = 8 - TAG = 9 def classify_head(l): if len(l) == 0: @@ -26,11 +27,11 @@ def classify_head(l): elif s == "]": return (TokType.CLOSE,None) elif s[:2] == "~~": - return (TokType.TAGGLOB, s[2:]) + return (LitType.TAGGLOB, s[2:]) elif s[:2] == "~-": - return (TokType.TITLEGLOB, s[2:]) + return (LitType.TITLEGLOB, s[2:]) else: - return (TokType.TAG, s) + return (LitType.TAG, s) class Atom: def __str__(self): @@ -77,8 +78,8 @@ def e4(l): if typ != TokType.CLOSE: raise ParseError return pt,l[1:] - elif typ == TokType.TAG: - return ParseTree(TokType.TAG, s), l[1:] + elif typ in LitType: + return Atom(typ, s), l[1:] else: raise ParseError diff --git a/test/t_queryparse.py b/test/t_queryparse.py index f3709d6..ac9cf24 100755 --- a/test/t_queryparse.py +++ b/test/t_queryparse.py @@ -12,3 +12,5 @@ f(["x", "y", "OR", "a", "b"]) f(["x", "y", "z", "w"]) f(["NOT", "x", "OR", "y"]) f(["NOT", "[", "x", "y", "z", "]"]) +f(["x", "y", "NOT", "z", "[", "a", "OR", "b", "]"]) +f(["~~internal-*", "~-Application*", "NOT", "~~*xyz*"]) |
