hledger icon indicating copy to clipboard operation
hledger copied to clipboard

boolean queries have surprising precedence when terms are space-separated

Open simonmichael opened this issue 8 months ago • 3 comments

Unless I'm confused, in our boolean queries, OR binds more tightly than AND ?

I don't want to change anyone's queries, but isn't this surprising and opposite to common practice in other systems, where OR is usually lowest precedence ?

Hopefully I'm confused and everything is fine.

Or, boolean queries are still a bit rough, and we have been unaware because we usually don't [need to] push them very hard. See also #2371.

simonmichael avatar Apr 19 '25 02:04 simonmichael

I think I was confused, assuming that space-separated terms inside a boolean query were combined with AND; they're not. I have fixed/expanded the doc at https://hledger.org/dev/hledger.html#boolean-queries and suggested avoiding space-separated terms inside boolean queries.

To be honest I haven't re-tested, but I trust the code comments which say that NOT, AND, OR are processed in that order, ie with standard precedence.

simonmichael avatar Apr 22 '25 22:04 simonmichael

If anyone thinks we should disallow space-separated terms inside boolean queries to reduce confusion, let me know.

simonmichael avatar Apr 22 '25 22:04 simonmichael