[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/queryparser - queryparser.py:1.1.2.5

Andreas Jung andreas@digicool.com
Wed, 16 Jan 2002 09:27:31 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/queryparser
In directory cvs.zope.org:/tmp/cvs-serv16501

Modified Files:
      Tag: ajung-textindexng-branch
	queryparser.py 
Log Message:
refactored queryparser


=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/queryparser/queryparser.py 1.1.2.4 => 1.1.2.5 ===
 
 import TextIndexG
-from Stack import Stack
+from Collector import Collector
 
-
-class QueryParser(Stack):
+class QueryParser(Collector):
 
     """Query parser takes a TextIndexNG query strings and transforms it
        into a Python expression to be evaluated.
@@ -33,11 +32,12 @@
     ANDREGEX       = 'and'
     ORREGEX        = 'or'
     STRREGEX       = '[a-zA-Z]*'
-
+    OPENPREGEX     = r'('
+    CLOSEPREGEX    = r')'
 
     def __init__(self):
 
-        Stack.__init__(self)
+        Collector.__init__(self)
 
         self.TextIndexG = TextIndexG.GRAMMAR()
 
@@ -46,26 +46,20 @@
         
     
     def DeclareTerminals(self):
-        self.TextIndexG.Addterm("and", self.ANDREGEX, self.operandToken)
-        self.TextIndexG.Addterm("or",  self.ORREGEX,  self.operandToken)
-        self.TextIndexG.Addterm("str", self.STRREGEX, self.wordFound)
-
-
-    def BindRules(self):
-        pass
+        self.TextIndexG.Addterm("openp",  self.OPENPREGEX,  self.addParens)
+        self.TextIndexG.Addterm("closep", self.CLOSEPREGEX, self.addParens)
+        self.TextIndexG.Addterm("and",    self.ANDREGEX,    self.addOp)
+        self.TextIndexG.Addterm("or",     self.ORREGEX,     self.addOp)
+        self.TextIndexG.Addterm("str",    self.STRREGEX,    self.addWord)
 
 
-    def wordFound(self,word):
-        print 'word:',word
-
-
-    def operandToken(self,op):
-        print 'operand',op
-
+    def BindRules(self): pass
 
     def __call__(self, query):
 
-        res = self.TextIndexG.DoParse1(query, {} )
+        self.TextIndexG.DoParse1(query, {} )
+        res = self.getResult()
+
         print res
        
         return res