[Groonga-commit] groonga/gcs [master] bq: throw exception for missing close parenthesis

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 6日 (月) 13:49:05 JST


Kouhei Sutou	2012-08-06 13:49:05 +0900 (Mon, 06 Aug 2012)

  New Revision: e087a1eefd13e651c672b444947bf0c7fe674413
  https://github.com/groonga/gcs/commit/e087a1eefd13e651c672b444947bf0c7fe674413

  Log:
    bq: throw exception for missing close parenthesis

  Modified files:
    lib/bq-translator.js
    test/bq-translator.test.js

  Modified: lib/bq-translator.js (+4 -8)
===================================================================
--- lib/bq-translator.js    2012-08-06 13:38:42 +0900 (e5f0752)
+++ lib/bq-translator.js    2012-08-06 13:49:05 +0900 (a5cb3d1)
@@ -91,12 +91,6 @@ BooleanQueryTranslator.prototype = {
           this.throwTranslateError("unknown operator: <" + operator + ">");
           break;
         }
-        this.skipSpaces();
-        if (this.query[this.offset] != ")") {
-          this.throwTranslateError("close parenthesis is missing " +
-                                   "for operator: <" + operator + ">");
-        }
-        this.offset++;
         return expression;
       } else if (character == ")") {
         this.throwTranslateError("operator is missing");
@@ -123,6 +117,7 @@ BooleanQueryTranslator.prototype = {
           this.throwTranslateError("a garbage character after value: " +
                                    "<" + character + ">");
         }
+        this.offset++;
         return expression;
       } else if (character == ")") {
         if (field.length == 0) {
@@ -137,8 +132,7 @@ BooleanQueryTranslator.prototype = {
       }
     }
 
-    // TODO: report error: missing close paren <)>
-    return "";
+    this.throwTranslateError("close parenthesis is missing: operator:<field>");
   },
   translateGroupFilter: function() {
     var field = "";
@@ -154,6 +148,7 @@ BooleanQueryTranslator.prototype = {
           // TODO: report error: have garbage
           return "";
         }
+        this.offset++;
         return expression;
       } else if (character == ")") {
         // TODO: report error: field and value is missing
@@ -172,6 +167,7 @@ BooleanQueryTranslator.prototype = {
     while (this.offset < this.query.length) {
       this.skipSpaces();
       if (this.query[this.offset] == ")") {
+        this.offset++;
         return "(" + expressions.join(" " + setOperator + " ") + ")";
       } else {
         expressions.push(this.translateExpression());

  Modified: test/bq-translator.test.js (+9 -4)
===================================================================
--- test/bq-translator.test.js    2012-08-06 13:38:42 +0900 (d790f83)
+++ test/bq-translator.test.js    2012-08-06 13:49:05 +0900 (3afa103)
@@ -130,10 +130,6 @@ suite('BoolanQueryTranslator', function() {
                  "(nonexistent f1:'k1' f2:'k2')",
                  "(nonexistent| |f1:'k1' f2:'k2')",
                  "unknown operator: <nonexistent>");
-  testGroupError("missing close parentheis: after operator",
-                 "(and f1:'k1' f2:'k2'",
-                 "(and f1:'k1' f2:'k2'||",
-                 "close parenthesis is missing for operator: <and>");
   testGroupError("missing close parentheis: in operator",
                  "(an",
                  "(an||",
@@ -163,6 +159,15 @@ suite('BoolanQueryTranslator', function() {
                  "(field fIeld 'value')",
                  "(field f|I|eld 'value')",
                  "invalid field character: <I>");
+  testGroupError("field: missing close parenthesis",
+                 "(field ",
+                 "(field ||",
+                 "close parenthesis is missing: operator:<field>");
+
+  // testGroupError("and: missing close parentheis",
+  //                "(and f1:'k1' f2:'k2'",
+  //                "(and f1:'k1' f2:'k2'||",
+  //                "close parenthesis is missing: operator:<and>");
 
   testExpression("value only: stirng: and: space",
                  "'keyword1 keyword2' 'other keyword'",
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index