textquery icon indicating copy to clipboard operation
textquery copied to clipboard

Tests say AND should have precedence over OR, test doesn't test it, code doesn't do it.

Open cjheath opened this issue 11 years ago • 0 comments

Multiple things wrong here:

  1. The code uses simple left-to-right precedence, it doesn't favour either AND or OR: https://github.com/igrigorik/textquery/blob/master/lib/textquery/textquery_grammar.treetop#L8

  2. The comment in the test shows OR having greater precedence, contrary to the meaning of "precedence" (binds tighter) and to the established principle from maths and logic. AND is the logical analog of multiplication, OR of addition, so the precedence in other systems always nests brackets around AND groups in preference to OR, like in mathematics. See <https://github.com/igrigorik/textquery/blob/master/spec/textquery_spec.rb#L52

  3. The test doesn't actually test for AND taking precedence in any case. https://github.com/igrigorik/textquery/blob/master/spec/textquery_spec.rb#L51-60

A patch is forthcoming on my branch.

cjheath avatar Aug 26 '13 01:08 cjheath