[Gnucash-changes] r13717 - gnucash/trunk - Tighten the grammar around quoted strings. Test-case fixes.

Joshua Sled jsled at cvs.gnucash.org
Thu Mar 30 19:00:43 EST 2006


Author: jsled
Date: 2006-03-30 19:00:43 -0500 (Thu, 30 Mar 2006)
New Revision: 13717
Trac: http://svn.gnucash.org/trac/changeset/13717

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/app-utils/test/test-exp-parser.c
   gnucash/trunk/src/calculation/expression_parser.c
Log:
Tighten the grammar around quoted strings.  Test-case fixes.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-03-30 20:59:38 UTC (rev 13716)
+++ gnucash/trunk/ChangeLog	2006-03-31 00:00:43 UTC (rev 13717)
@@ -13,6 +13,10 @@
 
 2006-03-30  Joshua Sled  <jsled at asynchronous.org>
 
+	* src/calculation/expression_parser.c (primary_exp):
+	* src/app-utils/test/test-exp-parser.c (test_parser): Tighten the
+	grammar around quoted strings. Test-case fixes.
+	
 	* src/calculation/expression_parser.c (primary_exp): 
 	* src/app-utils/test/test-exp-parser.c (test_parser): Add basic
 	validation and test-cases for invalid expressions.  Bugs#308554,

Modified: gnucash/trunk/src/app-utils/test/test-exp-parser.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-exp-parser.c	2006-03-30 20:59:38 UTC (rev 13716)
+++ gnucash/trunk/src/app-utils/test/test-exp-parser.c	2006-03-31 00:00:43 UTC (rev 13717)
@@ -39,6 +39,7 @@
   tests = g_list_append (tests, node);
 }
 
+
 #define add_fail_test(n,e,o) _add_fail_test((n), (e), (o), __FILE__, __LINE__)
 
 static void
@@ -134,6 +135,7 @@
   add_fail_test ("bad expression", "ç 1", 0);
   add_fail_test ("bad expression", "1 asdf", 6);
   add_fail_test ("bad expression", "asdf 1", 6);
+  add_fail_test ("bad expression", "asdf jkl", 8);
   add_fail_test ("bad expression", "  (5 + 23)/   ", 14);
   add_fail_test ("bad expression", "  ((((5 + 23)/   ", 17);
   add_fail_test ("divide by zero", "  4 / (1 - 1)", -1);
@@ -160,7 +162,7 @@
                  "- 42.72 + 13.32 + 15.48 + 23.4 + 115.4",
                  gnc_numeric_create(35897, 100) );
 
-  // This must be defined for the function-parsing to work.
+  /* This must be defined for the function-parsing to work. */
   scm_c_eval_string("(define (gnc:error->string tag args)   (define (write-error port)     (if (and (list? args) (not (null? args)))         (let ((func (car args)))           (if func               (begin                 (display \"Function: \" port)                 (display func port)                 (display \", \" port)                 (display tag port)                 (display \"\n\n\" port)))))     (false-if-exception      (apply display-error (fluid-ref the-last-stack) port args))     (display-backtrace (fluid-ref the-last-stack) port)     (force-output port))   (false-if-exception    (call-with-output-string write-error)))");
 
   scm_c_eval_string( "(define (gnc:plus a b) (+ a b))" );
@@ -193,8 +195,7 @@
   add_pass_test( "test_str( \"two\" : 2 )",  NULL, gnc_numeric_create( 4, 1 ) );
   add_fail_test( "test_str( 3 : \"three\" )", NULL, 23 );
   add_pass_test( "test_str( \"asdf\" : 1 )", NULL, gnc_numeric_create( 1, 1 ) );
-  // This used to work before the 334811, 308554 fixes... :/
-  //add_fail_test( "\"asdf\" + 0", NULL, 0 );
+  add_fail_test("\"asdf\" + 0", NULL, 8);
 
   scm_c_eval_string( "(define (gnc:blindreturn val) val)" );
   add_pass_test( "blindreturn( 123.1 )", NULL, gnc_numeric_create( 1231, 10 ) );

Modified: gnucash/trunk/src/calculation/expression_parser.c
===================================================================
--- gnucash/trunk/src/calculation/expression_parser.c	2006-03-30 20:59:38 UTC (rev 13716)
+++ gnucash/trunk/src/calculation/expression_parser.c	2006-03-31 00:00:43 UTC (rev 13717)
@@ -262,7 +262,7 @@
  * After parsing the above expressions the variables nni, jk, tyh and
  * tgh would all be defined.
  *
- * Functiosn are invoked with expressions of the format
+ * Functions are invoked with expressions of the format
  *
  *   [_a-zA-Z]( <argument_0> : <argument_1> : ... : <argument_n> )
  *
@@ -1226,9 +1226,13 @@
       rslt = get_named_var (pe);
       break;
     case STR_TOKEN:
-
-      if (check_expression_grammar_error(pe))
+      if (!(pe->Token == ')'
+            || pe->Token == ARG_TOKEN))
+      {
+        add_token(pe, EOS);
+        pe->error_code = EXPRESSION_ERROR;
         return;
+      }
 
       rslt = get_unnamed_var( pe );
       rslt->type = VST_STRING;



More information about the gnucash-changes mailing list