[Zope-CVS] CVS: Products/ZCTextIndex - QueryParser.py:1.1.2.10

Guido van Rossum guido@python.org
Sun, 5 May 2002 20:07:19 -0400


Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv22679

Modified Files:
      Tag: TextIndexDS9-branch
	QueryParser.py 
Log Message:
Change the second alternative for Term from ATOM to ATOM+.  This
allows queries like "hare brained" in addition to "hare-brained".  The
second one is (and was always) a single ATOM, and results in a single
call to search(term).  The first one now does the same; the term
argument being "hare brained" (which search() parses out in exactly
the same way, by virtue of the splitter we use).


=== Products/ZCTextIndex/QueryParser.py 1.1.2.9 => 1.1.2.10 ===
 AndExpr = Term ('AND' NotExpr)*
 NotExpr = ['NOT'] Term
-Term = '(' OrExpr ')' | ATOM
+Term = '(' OrExpr ')' | ATOM+
 
 An ATOM is a string not containing whitespace or parentheses, and not
 equal to one of the key words 'AND', 'OR', 'NOT'.  The key words are
-recognized in any mixture of case..
+recognized in any mixture of case.  Multiple consecutive ATOMs are
+accepted; these are reported as a single AtomNode whose value is the
+ATOM strings concatenated with a space.
 """
 
 import operator
@@ -89,6 +91,9 @@
         else:
             return 0
 
+    def _peek(self, tokentype):
+        return self.__tokentypes[self.__index] is tokentype
+
     def _get(self, tokentype):
         t = self.__tokens[self.__index]
         self._require(tokentype)
@@ -125,7 +130,10 @@
             tree = self._parseOrExpr()
             self._require(_RPAREN)
         else:
-            t = self._get(_ATOM)
+            atoms = [self._get(_ATOM)]
+            while self._peek(_ATOM):
+                atoms.append(self._get(_ATOM))
+            t = " ".join(atoms)
             tree = AtomNode(t)
         return tree