Skip to content

Python based RQL parser

Mantas Zimnickas requested to merge py-based-rql into master

Currently used pyrql is quite limited and overall RQL syntax is quite limited. One of the issues, is that there is no way to distinguish table column names from literals. For example:

eq(foo, bar)

There is no way of knowing if bar is a literal or a column. You need to assume, that by argument ordering, first eq() argument assumed to be column name and second a literal value.

If you need to compare one column to another, you could do:

eq(foo, bind(bar))

Or something like that. But this seems inconsistent.

Also there are issues with spaces. Currently pyrql just strips all trailing spaces, so there is no way to comare to a value that has traingin spaces is made just from spaces.

To fix those issues, I want to add a new Python pased RQL parse. Basically RQL syntax will be parsed as valid Python syntax. And literals from identifiers will be separated:

eq(foo, "bar")

Spaces are OK too:

eq(foo, " ") | eq(foo, "")

But there are several issues with Python based parser, because, Python uses = for assignment, not for comparison. So I think, this is ok, to use == instead of =. = can be left as is and can enable keyword arguments.

Another issues, is & and |. RQL is URL based and logical AND or OR is denoted with & and |. I think this is importand and I would like to keep it. In order to do that, I do AST rewriting, and change operator preceedence, givin higher priority to bitwise operators.

As mentioned, I will also add support for keyword arguments. And for chained method calls, like:

foo.lower().startswith("bar")

In RQL this would look:

startswith(lower(foo),"bar")

Both options will work, but I think in many cases, less nested first option is more readable.

#8

Merge request reports

Loading