aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Sloan2012-11-28 15:01:54 -0600
committerZachary Sloan2012-11-28 15:01:54 -0600
commita47111b7fce834924285d7a89b544c47473ce724 (patch)
tree8aee248a6fd4a5b09f143dc6a4a1906870413302
parentd1f2863c15f62ae37833fa1311870d7b1aab3355 (diff)
downloadgenenetwork2-a47111b7fce834924285d7a89b544c47473ce724.tar.gz
Changed parser.py to deal with the wild card character (*) and to split by
">" and "<" in addition to "=" and ":"
-rw-r--r--wqflask/wqflask/parser.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/wqflask/wqflask/parser.py b/wqflask/wqflask/parser.py
index 7711942a..a94a8842 100644
--- a/wqflask/wqflask/parser.py
+++ b/wqflask/wqflask/parser.py
@@ -27,23 +27,26 @@ from pprint import pformat as pf
def parse(pstring):
pstring = re.split(r"""(?:(\w+\s*=\s*[\(\[][^)]*[\)\]]) | # LRS=(1 2 3), cisLRS=[4 5 6], etc
- (\w+\s*[=:]\w+) | # wiki=bar, GO:foobar, etc
- (\w+)) # shh, brain, etc """, pstring,
+ (\w+\s*[=:\>\<][\w\*]+) | # wiki=bar, GO:foobar, etc
+ ([\w\*]+)) # shh, brain, etc """, pstring,
flags=re.VERBOSE)
pstring = [item.strip() for item in pstring if item and item.strip()]
print(pstring)
items = []
+ separators = [re.escape(x) for x in (":", "=", "<", ">")]
+ separators = '([%s])' % ("".join(separators))
+
+ print("separators:", separators)
+
for item in pstring:
- if ":" in item:
- key, seperator, value = item.partition(':')
- elif "=" in item:
- key, seperator, value = item.partition('=')
- else:
- seperator = None
+ splat = re.split(separators, item)
+ print("splat is:", splat)
- if seperator:
+ # splat is an array of 1 if no match, otherwise more than 1
+ if len(splat) > 1:
+ key, separator, value = splat
if '(' in value or '[' in value:
assert value.startswith(("(", "[")), "Invalid token"
assert value.endswith((")", "]")), "Invalid token"
@@ -51,19 +54,21 @@ def parse(pstring):
values = re.split(r"""\s+|,""", value)
value = [value.strip() for value in values if value.strip()]
term = dict(key=key,
- seperator=seperator,
+ separator=separator,
search_term=value)
else:
term = dict(key=None,
- seperator=None,
+ separator=None,
search_term = item)
items.append(term)
- print(pf(items))
+ print(pf(items) + "\n")
return(items)
if __name__ == '__main__':
parse("foo=[3 2 1]")
+ parse("WIKI=ho*")
+ parse("LRS>9")
parse("foo=[3 2 1)")
parse("foo=(3 2 1)")
parse("shh")