[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/queryparser - TextIndexGgen.py:1.1.2.2
Andreas Jung
andreas@digicool.com
Mon, 14 Jan 2002 15:39:03 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/queryparser
In directory cvs.zope.org:/tmp/cvs-serv29237
Modified Files:
Tag: ajung-textindexng-branch
TextIndexGgen.py
Log Message:
update
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/queryparser/TextIndexGgen.py 1.1.2.1 => 1.1.2.2 ===
STRREGEX = '[a-zA-Z]*'
-### declare interpretation functions and regex's for terminals
+OpMapping = {
+ 'or': 'txUnion',
+ 'and': 'txIntersection',
+ 'near': 'txNear'
+}
+
+### declare interpretation functions and regex's for terminals
class Stack:
@@ -89,7 +95,7 @@
if self._current:
r = ','.join(self._current)
- r = "%s(%s)" % (op, r)
+ r = "%s(%s)" % (OpMapping[op], r)
# get top element from stack
topEl,topOp = self.pop()
@@ -104,7 +110,7 @@
top1El,top1Op = self.pop()
r = ','.join(topEl)
- r = "%s(%s)" % (topOp, r)
+ r = "%s(%s)" % (OpMapping[topOp], r)
top1El.append(r)
@@ -118,19 +124,24 @@
def getResult(self):
if self._current:
+ if not self._op: self._op = self._default_op
+
r = ','.join(self._current)
- r = "%s(%s)" % (self._op, r)
+ r = "%s(%s)" % (OpMapping[self._op], r)
return r
else:
topEl,topOp = self.pop()
+ if not topOp: topOp = self._default_op
+
r = ','.join(topEl)
- r = "%s(%s)" % (topOp, r)
+ r = "%s(%s)" % (OpMapping[topOp], r)
return r
+C = Collector()
def openParens(x):
C.newLevel()
@@ -206,15 +217,15 @@
return TextIndexG
-########## test the grammar generation
-if REGENERATEONLOAD:
- print "(re)generating the TextIndexG grammar in file TextIndexG.py"
- Dummy = GrammarBuild()
- print "(re)generation done."
-
if __name__ == '__main__':
+ ########## test the grammar generation
+ if REGENERATEONLOAD:
+ print "(re)generating the TextIndexG grammar in file TextIndexG.py"
+ Dummy = GrammarBuild()
+ print "(re)generation done."
+
print "loading grammar as python"
TextIndexG = LoadTextIndexG()
@@ -224,7 +235,6 @@
'(a and b) or (c and dd)','a and (b or c or (x and y))']:
print '-'*78
- C = Collector()
print item
test = TextIndexG.DoParse1( item, Context)