From b5c22d3b4a54eed654c439eebf136f0770cd81c2 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Wed, 7 May 2014 13:15:49 -0400 Subject: [PATCH] More work. --- bitshift/query/__init__.py | 26 ++++++++++++++++++++++++-- bitshift/query/tree.py | 10 +++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/bitshift/query/__init__.py b/bitshift/query/__init__.py index d183bde..fc602f6 100644 --- a/bitshift/query/__init__.py +++ b/bitshift/query/__init__.py @@ -1,7 +1,12 @@ from .nodes import * ## TODO from .tree import Tree -__all__ = ["parse_query"] +__all__ = ["QueryParseException", "parse_query"] + +class QueryParseException(Exception): + """Raised by parse_query when a query is invalid.""" + pass + def parse_query(query): """ @@ -16,8 +21,25 @@ def parse_query(query): :return: A tree storing the data in the query. :rtype: :py:class:`~.query.tree.Tree` + + :raises: :py:class:`.QueryParseException` """ - pass + for term in query.split(" "): + pass + + language:"Python" + lang: + l: + + author:"Ben Kurtovic" + + modified:before + modified:after + created:before + created:after:"Jaunary 4, 2014" + + func:"foobar" + func:re|gex:"foo?b|car" # "foo" -> Tree() # "foo bar" -> "foo bar" OR ("foo" or "bar") diff --git a/bitshift/query/tree.py b/bitshift/query/tree.py index 3f09c0c..4c1b463 100644 --- a/bitshift/query/tree.py +++ b/bitshift/query/tree.py @@ -6,5 +6,13 @@ class Tree(object): def __init__(self, root): self._root = root + def __repr__(self): + return "Tree({0})".format(self._root) + def serialize(self): - pass + """Create a string representation of the query for caching. + + :return: Query string representation. + :rtype: str + """ + return repr(self)