From a440d3f0031a7171c77b4d0634f06fae6a43bfdd Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 23 Jun 2014 00:15:43 +0200 Subject: [PATCH] Fixed XPath operator precedence. Apparently using multiple `left` rules with T_AND and T_OR being separate solves this problem. Riiiiight.... --- lib/oga/xpath/parser.y | 3 ++- spec/oga/xpath/parser/operator_precedence_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/oga/xpath/parser.y b/lib/oga/xpath/parser.y index af8f440..f240392 100644 --- a/lib/oga/xpath/parser.y +++ b/lib/oga/xpath/parser.y @@ -12,7 +12,8 @@ options no_result_var prechigh left T_PIPE T_MOD T_DIV T_MUL T_SUB T_ADD - left T_GT T_GTE T_LT T_LTE T_NEQ T_EQ T_AND T_OR + left T_GT T_GTE T_LT T_LTE T_NEQ T_EQ + left T_AND T_OR preclow rule diff --git a/spec/oga/xpath/parser/operator_precedence_spec.rb b/spec/oga/xpath/parser/operator_precedence_spec.rb index 69cd6ce..99e107c 100644 --- a/spec/oga/xpath/parser/operator_precedence_spec.rb +++ b/spec/oga/xpath/parser/operator_precedence_spec.rb @@ -105,9 +105,9 @@ describe Oga::XPath::Parser do parse_xpath('A and B = C').should == s( :path, s( - :eq, - s(:and, s(:test, nil, 'A'), s(:test, nil, 'B')), - s(:test, nil, 'C') + :and, + s(:test, nil, 'A'), + s(:eq, s(:test, nil, 'B'), s(:test, nil, 'C')) ) ) end