From 34e629b3cd5ad5d09da4f22b9ef2f48baed26923 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 14 Apr 2014 10:01:34 -0400 Subject: [PATCH] Some early work on varous query objects. --- bitshift/query/__init__.py | 18 +++++++++++++++++- bitshift/query/associations.py | 29 +++++++++++++++++++++++++++++ bitshift/query/node.py | 4 ++++ bitshift/query/tree.py | 4 ++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 bitshift/query/associations.py create mode 100644 bitshift/query/node.py create mode 100644 bitshift/query/tree.py diff --git a/bitshift/query/__init__.py b/bitshift/query/__init__.py index 7d6e0d5..bc70cde 100644 --- a/bitshift/query/__init__.py +++ b/bitshift/query/__init__.py @@ -1,9 +1,25 @@ -from .association import Association +from .associations import BinaryOp, UnaryOp from .node import Node from .tree import Tree __all__ = ["parse_query"] def parse_query(query): + """ + Parse a search query. + + :param query: The query be converted. + :type query: str + + :return: A tree storing the data in the query. + :rtype: :py:class:`~.query.tree.Tree` + """ + + + + + "bubble sort lang:python" + + # gets a string, returns a Tree pass diff --git a/bitshift/query/associations.py b/bitshift/query/associations.py new file mode 100644 index 0000000..17e7a1e --- /dev/null +++ b/bitshift/query/associations.py @@ -0,0 +1,29 @@ +__all__ = ["BinaryOp", "UnaryOp"] + +class _Association(object): + pass + + +class BinaryOp(_Association): + AND = 1 + OR = 2 + + def __init__(self, left, right, op): + self.left = left + self.right = right + self.op = op + + def __str__(self): + ops = {AND: "And", OR: "Or"} + return "{0}({1}, {2})".format(ops[self.op], self.left, self.right) + + +class UnaryOp(_Association): + NOT = 1 + + def __init__(self, node, op): + self.node = node + self.op = op + + def __str__(self): + pass diff --git a/bitshift/query/node.py b/bitshift/query/node.py new file mode 100644 index 0000000..3317dac --- /dev/null +++ b/bitshift/query/node.py @@ -0,0 +1,4 @@ +__all__ = ["Node"] + +class Node(object): + pass diff --git a/bitshift/query/tree.py b/bitshift/query/tree.py new file mode 100644 index 0000000..90702dc --- /dev/null +++ b/bitshift/query/tree.py @@ -0,0 +1,4 @@ +__all__ = ["Tree"] + +class Tree(object): + pass