Opened 14 years ago
Last modified 12 months ago
#521 new defect
Precedence of HATE is surprising
Reported by: | Olly Betts | Owned by: | Olly Betts |
---|---|---|---|
Priority: | normal | Milestone: | 2.0.0 |
Component: | QueryParser | Version: | 1.2.3 |
Severity: | normal | Keywords: | |
Cc: | dcolish@… | Blocked By: | |
Blocking: | Operating System: | All |
Description (last modified by )
This query:
a OR b -c
gets parsed as:
a OR (b -c)
rather than the more obvious interpretation of:
(a OR b) -c
While this appears to be just a precedence issue, actually HATE is resolved within a "term group" and b -c
is a term group here, so this might take a bit of reworking to fix.
Attachments (1)
Change History (10)
comment:1 by , 14 years ago
Description: | modified (diff) |
---|
comment:3 by , 14 years ago
Sorry, that grammar paste didnt work out too well. I've got it pasted: http://paste.pocoo.org/raw/347500/
comment:4 by , 14 years ago
Took a shot at getting this refactored, i think it will make a little more sense not that we're not trying to explicitly match each possible combination of expressions, and instead letting the expressions reduce themselves. There might be some right recursion in it which needs to be factored out more.
comment:5 by , 14 years ago
Cc: | added |
---|
comment:6 by , 13 years ago
There are some problems with the grammar in grammar.out.
One is easily fixed - expr can be a term but can also be a prob which can be a term. I think you don't want to allow expr to be a term directly.
The rules for group and phrase_term also seem to be wrong - these needs to start with a TERM, but your rules seem to mean it's the last but one token which needs to be a TERM. I think the recursive rule in each case needs its RHS transposing.
But there are other issues which seem harder to address - for example, you can specify arbitrary numbers of PLUS and MINUS in a row (because unop loops back to expr). Also even without that, you can write: term1 PLUS PLUS term2 (first PLUS from binop, second from unop).
comment:7 by , 12 years ago
Milestone: | 1.2.x → 1.3.x |
---|
After looking briefly at the grammar, I think a good refactoring will be needed to support this style of precedence. The main issue is that the grammar will branch on the boolean operators before ever considering the hate/love operators. This means that even with precedence weight changes, the grammar could not support the expected output. One way to resolve this is to classify all binary expressions and reduce those. This way, the potential reduction of '-' before 'AND' will be controlled by the precedence of operators. Another approach would be to structure the grammar to ensure the LOVE/HATE operators are reduced before the boolean ones; however, this could also have unintended side-effects. I did dump out the lemon grammar as it stands::