[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ add tests and missing implementations to the parser
Charith Paranaliyanage
paranaliyanage at gmail.com
Mon Sep 1 15:46:23 EDT 2008
Log message for revision 90663:
add tests and missing implementations to the parser
Changed:
U Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt
U Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py
U Sandbox/adamg/ocql/trunk/src/ocql/queryobject/interfaces.py
U Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py
U Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject_checks.txt
-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt 2008-09-01 17:24:46 UTC (rev 90662)
+++ Sandbox/adamg/ocql/trunk/src/ocql/parser/parser.txt 2008-09-01 19:46:21 UTC (rev 90663)
@@ -156,3 +156,24 @@
In(Identifier(d), Identifier(IDepartment));
Eq(Identifier(d), Quanted((Some, ''), Property(Identifier(c), Identifier(runBy)))),
Property(Identifier(d), Identifier(name))))
+
+ >>> QueryParser("set [ c in ICourse; d in set{1 ... 4}; d == some c.credits | c.code ]")(None)
+ Head(Query(<type 'set'>,
+ In(Identifier(c), Identifier(ICourse));
+ ConstantSet(<type 'set'>, Identifier(d), Range(Constant(1), Constant(4)));
+ Eq(Identifier(d), Quanted((Some, ''), Property(Identifier(c), Identifier(credits)))),
+ Property(Identifier(c), Identifier(code))))
+
+ >>> QueryParser("set [ c in ICourse; d in set{1, 2}; d == some c.credits | c.code ]")(None)
+ Head(Query(<type 'set'>,
+ In(Identifier(c), Identifier(ICourse));
+ ConstantSet(<type 'set'>, Identifier(d), [Constant(1), Constant(2)]);
+ Eq(Identifier(d), Quanted((Some, ''), Property(Identifier(c), Identifier(credits)))),
+ Property(Identifier(c), Identifier(code))))
+
+ >>> QueryParser("set [ c in ICourse; d in set{}; d == some c.credits | c.code ]")(None)
+ Head(Query(<type 'set'>,
+ In(Identifier(c), Identifier(ICourse));
+ ConstantSet(<type 'set'>, Identifier(d), []);
+ Eq(Identifier(d), Quanted((Some, ''), Property(Identifier(c), Identifier(credits)))),
+ Property(Identifier(c), Identifier(code))))
Modified: Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py 2008-09-01 17:24:46 UTC (rev 90662)
+++ Sandbox/adamg/ocql/trunk/src/ocql/parser/queryparser.py 2008-09-01 19:46:21 UTC (rev 90663)
@@ -41,8 +41,8 @@
tokens = ('SET', 'LIST', 'COMMA', 'NOT_EQUAL', 'UNION', 'AS', 'EVERY',
'ATMOST', 'LT', 'GT', 'ELLIPSIS', 'BRACKET_R', 'OR', 'PIPE',
'DOT', 'IN', 'LTE', 'SOME', 'AND', 'CBRACKET_L', 'CONSTANT',
- 'EQUAL', 'GTE', 'ISINSTANCE', 'SEMI_COLON', 'BRACKET_L', 'ASSIGN',
- 'NOT_ASSIGN', 'FOR', 'CBRACKET_R', 'JUST', 'IDENTIFIER', 'DIFFER',
+ 'EQUAL', 'GTE', 'ISINSTANCE', 'SEMI_COLON', 'BRACKET_L',
+ 'FOR', 'CBRACKET_R', 'JUST', 'IDENTIFIER', 'DIFFER',
'LEN', 'BAG', 'SBRACKET_L', 'NOT', 'ATLEAST', 'SBRACKET_R',
'PLUS', 'MINUS', 'MUL', 'DIV')
@@ -231,14 +231,6 @@
r'\)'
return t
- def t_ASSIGN(self, t):
- r'='
- return t
-
- def t_NOT_ASSIGN(self, t):
- r'~='
- return t
-
def t_PLUS(self, t):
r'\+'
return t
@@ -312,19 +304,12 @@
t[0] = Div(self.metadata, self.symbols, t[1], t[3])
if DEBUG: print 'reducing "expression UNION expression" to "expression"', t[0]
-# def p_expr_3(self, t):
-# r'''expression : collection SBRACKET_L expression SBRACKET_R
-# '''
-# t[0] = Query(self.metadata, self.symbols, t[1], [], t[3])
-# if DEBUG: print 'reducing "collection SBRACKET_L qualifier PIPE expression SBRACKET_R" to "expression"'
-
def p_expr_query(self, t):
r'''expression : collection SBRACKET_L qualifier PIPE expression SBRACKET_R
'''
t[0] = Query(self.metadata, self.symbols, t[1], t[3], t[5])
if DEBUG: print 'reducing "collection SBRACKET_L qualifier PIPE expression SBRACKET_R" to "expression"', t[0]
-#TODO add a test
def p_expr_for_query(self, t):
r'''expression : collection SBRACKET_L expression FOR qualifier SBRACKET_R
'''
@@ -404,12 +389,6 @@
t[0] = t[1]
if DEBUG: print 'reducing "qualifier SEMI_COLON qualifier" to "qualifier"', t[0]
-# def p_qualifier_6(self, t):
-# r'''qualifier : expression
-# '''
-# t[0] = t[1]
-# if DEBUG: print 'reducing "expression" to "qualifier"'
-
def p_generator_in(self, t):
r'''generator : IDENTIFIER IN expression
'''
@@ -421,6 +400,18 @@
t[3])
if DEBUG: print 'reducing "IDENTIFIER IN expression" to "generator"', t[0]
+ def p_constantset_in(self, t):
+ r'''generator : IDENTIFIER IN collection CBRACKET_L element_list CBRACKET_R
+ '''
+ t[0] = ConstantSet(self.metadata,
+ self.symbols,
+ t[3],
+ Identifier(self.metadata,
+ self.symbols,
+ t[1]),
+ t[5])
+ if DEBUG: print 'IDENTIFIER IN collection CBRACKET_L element CBRACKET_R', t[0]
+
def p_filter_and(self, t):
r'''filter : filter AND filter
'''
@@ -451,18 +442,6 @@
t[0] = t[2]
if DEBUG: print 'reducing "BRACKET_L filter BRACKET_R" to "condition"', t[0]
- def p_condition_assign(self, t):
- r'''condition : quantified ASSIGN quantified
- '''
- raise NotImplementedError('assign')
- if DEBUG: print 'reducing "quantified operator quantified" to "condition"', t[0]
-
- def p_condition_not_assign(self, t):
- r'''condition : quantified NOT_ASSIGN quantified
- '''
- raise NotImplementedError('not assign')
- if DEBUG: print 'reducing "quantified operator quantified" to "condition"', t[0]
-
def p_condition_lt(self, t):
r'''condition : quantified LT quantified
'''
@@ -556,35 +535,29 @@
t[0] = Constant(self.metadata, self.symbols, t[1])
if DEBUG: print 'reducing "CONSTANT" to "literal"', t[0]
- def p_literal_element(self, t):
- r'''literal : collection CBRACKET_L element CBRACKET_R
- '''
- raise NotImplementedError('collection set')
- if DEBUG: print 'reducing "collection CBRACKET_L element CBRACKET_R" to "literal"', t[0]
-
def p_element_null(self, t):
- r'''element :
+ r'''element_list :
'''
- t[0] = None
+ t[0] = []
if DEBUG: print 'reducing "" to "element"', t[0]
def p_element_expression(self, t):
- r'''element : expression
+ r'''element_list : expression
'''
- t[0] = t[1]
+ t[0] = [t[1]]
if DEBUG: print 'reducing "expression" to "element"', t[0]
-# Why this raise a shift/reduce conflict
-# def p_element_comma(self, t):
-# r'''element : element COMMA element
-# '''
-# raise NotImplementedError('element list')
-# if DEBUG: print 'reducing "element COMMA element" to "element"', t[0]
+ def p_element_element(self, t):
+ r'''element_list : element_list COMMA expression
+ '''
+ t[1].append(t[3])
+ t[0] = t[1]
+ if DEBUG: print 'reducing "qualifier SEMI_COLON qualifier" to "qualifier"', t[0]
def p_element_ellipsis(self, t):
- r'''element : expression ELLIPSIS expression
+ r'''element_list : expression ELLIPSIS expression
'''
- raise NotImplementedError('range')
+ t[0] = Range(self.metadata, self.symbols, t[1], t[3])
if DEBUG: print 'reducing "expression ELLIPSIS expression" to "element"', t[0]
def p_path_identifier(self, t):
Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/interfaces.py 2008-09-01 17:24:46 UTC (rev 90662)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/interfaces.py 2008-09-01 19:46:21 UTC (rev 90663)
@@ -77,6 +77,14 @@
terms = Attribute('terms')
target = Attribute('target')
+class IConstantSet(ITerm):
+ """Objects providing this interface represent the
+ Constant Set Query object
+ """
+ collection_type = Attribute('collection type')
+ identifier = Attribute('identifier')
+ terms = Attribute('terms')
+
class IIn(ITerm):
"""Objects providing this interface represent the
In Query object
@@ -87,6 +95,14 @@
Alias Query object
"""
+class IRange(ITerm):
+ """Objects providing this interface represent the
+ Range Query object
+ """
+ collection = Attribute('collection type')
+ start = Attribute('range start point')
+ end = Attribute('range end point')
+
class IBinary(IExpression):
"""Objects providing this interface represent the
Binary Query object
Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py 2008-09-01 17:24:46 UTC (rev 90662)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject.py 2008-09-01 19:46:21 UTC (rev 90663)
@@ -206,6 +206,35 @@
def get_collection_type(self, klass=None):
return self.collection_type
+class ConstantSet(Term):
+ implements(IConstantSet)
+
+ def __init__(self, metadata, symbols, collection_type, identifier, elements):
+ self.metadata = metadata
+ self.symbols = symbols
+ Child.__init__(self)
+ self.setProp('collection_type', collection_type)
+ self.setProp('identifier', identifier)
+ if isinstance(elements, Range):
+ self.setProp('elements', elements)
+ else:
+ self.setProperties('elements', elements)
+
+ def addSymbol(self):
+ s = self.symbols.current()
+ s[self.identifier] = self.__class__.__name__
+
+ def get_collection_type(self):
+ return self.__class__.__name__
+
+ def __repr__(self):
+ return "%s(%s, %s, %s)" % (
+ self.__class__.__name__,
+ str(self.collection_type),
+ str(self.identifier),
+ str(self.elements)
+ )
+
class In(Term):
implements(IIn)
def __repr__(self):
@@ -246,6 +275,23 @@
#print self.expression.name,rv
return rv
+class Range(Term):
+ implements(IRange)
+
+ def __init__(self, metadata, symbols, start, end):
+ self.metadata = metadata
+ self.symbols = symbols
+ Child.__init__(self)
+ self.setProp('start', start)
+ self.setProp('end', end)
+
+ def __repr__(self):
+ return "%s(%s, %s)" % (
+ self.__class__.__name__,
+ str(self.start),
+ str(self.end)
+ )
+
#
# Binary operators
#
Modified: Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject_checks.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject_checks.txt 2008-09-01 17:24:46 UTC (rev 90662)
+++ Sandbox/adamg/ocql/trunk/src/ocql/queryobject/queryobject_checks.txt 2008-09-01 19:46:21 UTC (rev 90663)
@@ -65,6 +65,11 @@
>>> verifyObject(IQuery, Query(metadata, symbols, set, [child], child))
True
+ >>> verifyClass(IConstantSet, ConstantSet)
+ True
+ >>> verifyObject(IConstantSet, ConstantSet(metadata, symbols, set, child, [child]))
+ True
+
>>> verifyClass(IIn, In)
True
>>> verifyObject(IIn, In(metadata, symbols, child, child))
@@ -75,6 +80,11 @@
>>> verifyObject(IAlias, Alias(metadata, symbols, child, child))
True
+ >>> verifyClass(IRange, Range)
+ True
+ >>> verifyObject(IRange, Range(metadata, symbols, child, child))
+ True
+
>>> verifyClass(IBinary, Binary)
True
>>> verifyObject(IBinary, Binary(metadata, symbols, child, child))
More information about the Checkins
mailing list