Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
New query parser with numeric expressions and query plugins #1799
This is a rewrite of the code for parsing queries. This allows numeric expressions such as "length + 8 seconds", "playcount * 2", and "(1-rating)*5 days" to be used on both the right and left side of numeric comparisons. Any numerical comparisons that parsed before should still work the same.
This also adds a "@(plugin)" syntax for plugins to extend queries with custom types of searches. This is backwards incompatible with some queries containing '@', however. Three query plugins are included: conditional queries, python expression queries, and including saved searches in queries.
The syntax for the query plugins:
Implementation-wise, this parser parses through each character individually instead of having a separate lexer, which allows the numerical expressions to be much more easily parsed.
The interface of the quodlibet.query.Query class is identical to before, although the internal implementation has changed somewhat.
The following test cases have been added to cover the additions:
The test case TNumericOp in tests/test_query__match.py was removed because it contained only tests pertaining to the previous parser implementation.
I've tried to be backwards compatible with the old parser wherever possible. As far as I can tell, the only exception to this is queries containing '@' (which is now a special character).
This does keep backwards compatibility with date expressions such as '2007-07-19' in numeric comparisons by interpreting them as dates if the comparison contains a 'date' tag and as subtraction otherwise.
Sorry for the delay..
On the pull request:
On the implementation/features:
Why isn't it possible to implement the numeric expressions on top of the
I figured this pull request would be fairly unexpected, but after writing it primarily for my own use I decided to make a pull request in case it's worth including in the main project.
As for the implementation, the lexer parsed all
If the loss of backwards compatibility with
I see, thanks. I would hav epreferred if the numexp parsing was separate, but the new code looks readable/documented enough..
I don't think that's a big problem..
One problem I see is that spaces in tags no longer work and escaping them doesn't help. e.g.
added a commit
this pull request
Feb 1, 2016
With the python expression query plugin:
With the saved search plugin:
With the conditional plugin:
None of these work unless the corresponding plugin is first enabled in the plugins menu.