[gnome-calculator/gnome-3-22] Fixed first expression with parentheses (bgo#700617)



commit 0a02131392ca40bb82f11570a0bb3a9991a3dbbb
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Oct 21 01:01:18 2016 +0300

    Fixed first expression with parentheses (bgo#700617)

 lib/equation-parser.vala |   15 ++++++++++++++-
 tests/test-equation.vala |    2 ++
 2 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/lib/equation-parser.vala b/lib/equation-parser.vala
index 994e11d..20ecdd6 100644
--- a/lib/equation-parser.vala
+++ b/lib/equation-parser.vala
@@ -1564,7 +1564,20 @@ public class Parser
             if (token.type == LexerTokenType.R_R_BRACKET)
             {
                 depth_level--;
-                return true;
+                token = lexer.get_next_token ();
+                lexer.roll_back ();
+
+                if (token.type == LexerTokenType.NUMBER)
+                {
+                    insert_into_tree (new MultiplyNode (this, null, make_precedence_p (Precedence.MULTIPLY), 
get_associativity_p (Precedence.MULTIPLY)));
+
+                    if (!expression ())
+                        return false;
+                    else
+                        return true;
+                 }
+                 else
+                     return true;
             }
             //Expected ")" here...
             else
diff --git a/tests/test-equation.vala b/tests/test-equation.vala
index 76d1250..d7e48ab 100644
--- a/tests/test-equation.vala
+++ b/tests/test-equation.vala
@@ -360,6 +360,8 @@ private void test_equations ()
     test ("(1+2)×3", "9", 0);
     test ("(1+2×3)", "7", 0);
     test ("2(1+1)", "4", 0);
+    test ("(2)1+1", "3", 0);
+    test ("(2)(1)", "2", 0);
     test ("4÷2(1+1)", "4", 0);
 
     /* Percentage */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]