> Big sigh!  I just finished building my rpms, and uploaded them to
> ftp://ftp.htdig.org/incoming/, then I discovered a minor glitch in the
> parser error messages.  A query string of "(tool and not bar)" now gives
> the error message:
> 
>       Expected a search word instead of '!' or 'NOT' instead of ')' 
> 
> The extra instead of ')' seems to happen because the parser code seems to
> keep going, even after it detects an invalid syntax.  Usually, it would
> just replace one error string with another, but my little addition to the
> factor() function just appends to whatever is there.  I'm working on a
> patch for this, but I don't know whether this should hold up the release
> or not.

OK, here's my patch for this, to be applied to the 3.1.1 final release.
Sorry about not catching this sooner.  Now, it only gives a message for
the first error found, and doesn't add extra junk when it shouldn't.
In the process, I managed to tidy things up too.  Please give this a try.

--- ./htsearch/parser.h.errors2 Tue Feb 16 23:03:56 1999
+++ ./htsearch/parser.h Wed Feb 17 14:58:44 1999
@@ -34,6 +34,7 @@
     void               term(int);
     void               factor(int);
     int                        match(int);
+    void               setError(char *);
     void               perform_push();
     void               perform_and(int);
     void               perform_or();
--- ./htsearch/parser.cc.errors2        Tue Feb 16 23:03:56 1999
+++ ./htsearch/parser.cc        Wed Feb 17 15:08:44 1999
@@ -34,8 +34,6 @@
 Parser::checkSyntax(List *tokenList)
 {
     tokens = tokenList;
-    tokens->Start_Get();
-    lookahead = lexan();
     valid = 1;
     fullexpr(0);
     return valid;
@@ -45,19 +43,12 @@
 void
 Parser::fullexpr(int output)
 {
+    tokens->Start_Get();
+    lookahead = lexan();
     expr(output);
-    if (lookahead != DONE)
+    if (valid && lookahead != DONE)
     {
-       valid = 0;
-       error = 0;
-       error << "Expected end of expression instead of '";
-       error << current->word.get() << '\'';
-       switch (lookahead)
-       {
-       case '&':       error << " or 'AND'";   break;
-       case '|':       error << " or 'OR'";    break;
-       case '!':       error << " or 'NOT'";   break;
-       }
+       setError("end of expression");
     }
 }
 
@@ -107,12 +98,9 @@
        else
            break;
     }
-    if (lookahead == WORD)
+    if (valid && lookahead == WORD)
     {
-       valid = 0;
-       error = 0;
-       error << "Expected 'AND' or 'OR' instead of '" << current->word.get();
-       error << '\'';
+       setError("'AND' or 'OR'");
     }
 }
 
@@ -151,9 +139,7 @@
        }
        else
        {
-           valid = 0;
-           error = 0;
-           error << "Expected ')'";
+           setError("')'");
        }
     }
     else if (lookahead == WORD)
@@ -166,13 +152,32 @@
     }
     else
     {
-       valid = 0;
-       error = 0;
-       error << "Expected a search word";
+       setError("a search word");
     }
+}
 
-    if (!valid)
+//*****************************************************************************
+int
+Parser::match(int t)
+{
+    if (lookahead == t)
     {
+       lookahead = lexan();
+       return 1;
+    }
+    else
+       return 0;
+}
+
+//*****************************************************************************
+void
+Parser::setError(char *expected)
+{
+    if (valid)
+    {
+       valid = 0;
+       error = 0;
+       error << "Expected " << expected;
        if (lookahead == DONE || !current)
        {
            error << " at the end";
@@ -192,19 +197,6 @@
 }
 
 //*****************************************************************************
-int
-Parser::match(int t)
-{
-    if (lookahead == t)
-    {
-       lookahead = lexan();
-       return 1;
-    }
-    else
-       return 0;
-}
-
-//*****************************************************************************
 // Perform a lookup of the current word and push the result onto the stack
 //
 void
@@ -409,8 +401,6 @@
 Parser::parse(List *tokenList, ResultList &resultMatches)
 {
     tokens = tokenList;
-    tokens->Start_Get();
-    lookahead = lexan();
     fullexpr(1);
 
     ResultList *result = (ResultList *) stack.pop();


-- 
Gilles R. Detillieux              E-mail: <[EMAIL PROTECTED]>
Spinal Cord Research Centre       WWW:    http://www.scrc.umanitoba.ca/~grdetil
Dept. Physiology, U. of Manitoba  Phone:  (204)789-3766
Winnipeg, MB  R3E 3J7  (Canada)   Fax:    (204)789-3930
------------------------------------
To unsubscribe from the htdig3-dev mailing list, send a message to
[EMAIL PROTECTED] containing the single word "unsubscribe" in
the SUBJECT of the message.

Reply via email to