Fix parsing of logical expressions#73
Conversation
Do not ignore max_precedence in calls to parse_logical.
|
Good catch! I will merge it. Thanks for the patch :) |
Fix parsing of logical expressions
|
I'm sorry, this fix is incorrect. Parser is trying to use different precedence for The current behaviour is still wrong as they associate right to left. Changing logical_precedence table to set equal precedence for all logical operators seems to fix that. I just saw the merge update while typing this. Oops. |
|
So, the parsing of logical expressions could be simplified a bit. There is also this strange branch which looks incorrect to me - things like |
|
I think setting equal precedence for 'and' and 'or' logical operators won't fix the correct evaluation of the expression. Since function 'parse_logical' doesn't pass down 'max_precedence' to 'parse_logical_or_arithmetic', 'max_precedence' is always the lowest precedence and expressions are evaluated right-to-left. So whereas 'and' and 'or' should have equal precedence according to the spec, I think your patch is still correct. With regard to the strange branch you mentioned, initially there was some misunderstanding about how the expression "tcp port 80" should be parsed. It was thought to be parsed as "tcp and port 80" but that proved to be wrong, as "tcp port 80" is itself an operator. There's an issue opened about removing this implicit conjunction #16. |
|
Am I correct that should implicit conjunction be removed, the body of that branch should be replaced with something like |
Currently
parse_logicaldoes not passmax_precedencetoparse_logical_or_arithmetic, and, as defaultmax_precedenceismath.huge, effectively all logical operators have same precedence and are right associative.Testcase:
Result before fix:
Result after fix:
Also added a test for this.