[Erp5-report] r26803 - /erp5/trunk/products/ZSQLCatalog/SearchText/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue May 5 14:22:26 CEST 2009
Author: vincent
Date: Tue May 5 14:22:24 2009
New Revision: 26803
URL: http://svn.erp5.org?rev=26803&view=rev
Log:
Make AdvancedSearchTextParser behaviour relative to unknown column names coherent with AdvancedSearchtextDetector's behaviour.
Update embeded test.
Modified:
erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextParser.py
erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py
erp5/trunk/products/ZSQLCatalog/SearchText/lexer.py
Modified: erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextParser.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextParser.py?rev=26803&r1=26802&r2=26803&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextParser.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchText/AdvancedSearchTextParser.py [utf8] Tue May 5 14:22:24 2009
@@ -148,6 +148,48 @@
class AdvancedSearchTextParser(lexer):
+ # IMPORTANT:
+ # In short: Don't remove any token definition below even if they look
+ # useless.
+ # In detail: The lex methods below are redefined here because of ply nice
+ # feature of prioritizing tokens using the *line* *number* at which they
+ # are defined. As we inherit those methods from another class from another
+ # file (which doesn't match this file's content, of course) we must redefine
+ # wrapper methods to enforce token priority. Kudos to ply for so much
+ # customisable behaviour. Not.
+
+ def t_LEFT_PARENTHESE(self, t):
+ return lexer.t_LEFT_PARENTHESE(self, t)
+
+ def t_RIGHT_PARENTHESE(self, t):
+ return lexer.t_RIGHT_PARENTHESE(self, t)
+
+ def t_OPERATOR(self, t):
+ return lexer.t_OPERATOR(self, t)
+
+ def t_STRING(self, t):
+ return lexer.t_STRING(self, t)
+
+ def t_COLUMN(self, t):
+ if self.isColumn(t.value[:-1]):
+ t = lexer.t_COLUMN(self, t)
+ else:
+ # t is a non-existing column, so it should be taken as a string prefix.
+ t.type = 'STRING_PREFIX'
+ return t
+
+ def t_OR(self, t):
+ return lexer.t_OR(self, t)
+
+ def t_AND(self, t):
+ return lexer.t_AND(self, t)
+
+ def t_NOT(self, t):
+ return lexer.t_NOT(self, t)
+
+ def t_WORD(self, t):
+ return lexer.t_WORD(self, t)
+
def p_seach_text(self, p):
'''search_text : and_expression
| and_expression OR search_text'''
@@ -225,8 +267,19 @@
def p_string(self, p):
'''string : WORD
- | STRING'''
- p[0] = p[1]
+ | STRING
+ | STRING_PREFIX string'''
+ if len(p) == 3:
+ p[0] = p[1] + p[2]
+ else:
+ p[0] = p[1]
+
+ def __call__(self, input, is_column, *args, **kw):
+ self.isColumn = is_column
+ try:
+ return self.parse(input, *args, **kw)
+ finally:
+ self.isColumn = None
update_docstrings(AdvancedSearchTextParser)
Modified: erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py?rev=26803&r1=26802&r2=26803&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchText/SearchTextParser.py [utf8] Tue May 5 14:22:24 2009
@@ -72,7 +72,7 @@
@profiler_decorator
def _parse(input, is_column, *args, **kw):
if isAdvancedSearchText(input, is_column):
- result = getAdvancedSearchTextParser()(input, *args, **kw)
+ result = getAdvancedSearchTextParser()(input, is_column, *args, **kw)
else:
result = None
return result
@@ -222,7 +222,7 @@
('(a AND b) OR (c AND (d OR e))',
ComplexQuery([ComplexQuery([Query(None, 'a'), Query(None, 'b')], operator='and'), ComplexQuery([Query(None, 'c'), ComplexQuery([Query(None, 'd'), Query(None, 'e')], operator='or')], operator='and')], operator='or')),
('(foo:"") (bar:baz)', ComplexQuery([Query('foo', ''), Query('bar', 'baz')], operator='and')),
- ('(foo:"") (OR:bar)', ComplexQuery([Query('foo', ''), Query('OR', 'bar')], operator='and')),
+ ('(foo:"") (OR:bar)', ComplexQuery([Query('foo', ''), Query(None, 'OR:bar')], operator='and')),
# ('foo: OR', ['foo', 'or']),
# ('foo: OR ', ['foo', 'or']),
# ('(foo:)', ['foo', '']),
@@ -328,12 +328,15 @@
print ' Detector: %r' % (detector_result, )
if detector_result:
print ' LEX:'
- lexer = getAdvancedSearchTextParser().lexer
+ advanced_parser = getAdvancedSearchTextParser()
+ lexer = advanced_parser.lexer
+ advanced_parser.isColumn = isColumn
lexer.input(input)
while 1:
tok = lexer.token()
if not tok: break # No more input
print ' %s' % (tok, )
+ advanced_parser.isColumn = None
print ' YACC:'
print ' %r' % (parse(input, debug=2), )
else:
Modified: erp5/trunk/products/ZSQLCatalog/SearchText/lexer.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchText/lexer.py?rev=26803&r1=26802&r2=26803&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchText/lexer.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchText/lexer.py [utf8] Tue May 5 14:22:24 2009
@@ -82,6 +82,7 @@
'NOT',
'COLUMN',
'STRING',
+ 'STRING_PREFIX',
'WORD',
'OPERATOR',
'LEFT_PARENTHESE',
@@ -146,7 +147,8 @@
kw['lexer'] = self
return self.parser.parse(*args, **kw)
- __call__ = parse
+ def __call__(self, input, is_column, *args, **kw):
+ raise NotImplementedError
def update_docstrings(klass):
for property in dir(klass):
More information about the Erp5-report
mailing list