yaacov / tree-search-language

Tree Search Language (TSL) is a wonderful search langauge.
Apache License 2.0
61 stars 11 forks source link

Support boolean TRUE / FALSE literal values #10

Closed cben closed 4 years ago

cben commented 5 years ago

Parsing e.g. managed = FALSE fails. Indeed the grammar doesn't have boolean literals: https://github.com/yaacov/tree-search-language/blob/b3a2bd7a1518111c50fd7235d153c52285e2d113/TSL.g4#L42-L45

Using managed = 0, managed != 1 instead seems to work (using SQL walker, in backend for cloud.redhat.com/openshift). But this is not what user expects for a boolean field.

cben commented 5 years ago

I can work on this unless you beat me to it.

yaacov commented 5 years ago

I can work on this unless you beat me to it.

I do not think I will beat you to it :-)

p.s. we have a workaround using strings e.g. 'false' and 'true' see: https://github.com/yaacov/tree-search-language/blob/36e7e9f7edc10fbdc961a870e13b8cb5d800703e/pkg/walkers/semantics/walk.go#L137

yaacov commented 5 years ago

p.p.s using strings to represent boolean is not that uncommon: http://www.postgresqltutorial.com/postgresql-boolean/

cben commented 5 years ago

Thanks.
That workaround is in Semantics walker; doesn't work with SQL walker
CORRECTION: workaround did work for me. SQL walker doesn't know column types, it passes all consts though to the generated SQL and as I happen to use Postgres, which does accept 'f', 'false', '0' etc.

This differs by DB of course. E.g. in SQLite and MySQL booleans are just alias to integers https://modern-sql.com/blog/2019-01/sqlite-in-2018#boolean

I still want to add true boolean literals support to TSL syntax.

yaacov commented 4 years ago

fixed by https://github.com/yaacov/tree-search-language/pull/21