QPL Parsing, uses a custom grammar implemented with LARK, a modern general-purpose parsing library for Python, with it we can parse the query using the grammar and a LALR(1) parser.
Parsing a query with QPL is as simple as it gets, we start by importing the QPLOptions and the QPLParser
from pyqpl.qpl import QPLOptions from pyqpl.parser import QPLParser
QPLOptions is the one which will said the grammar to use and the rules to apply,
options = QPLOptions(fields='content', implicit_operator='or', wildcard=False)
implicit_operator
option, accepts either 'or' or 'and', this option select grammars with a slight variation between them, to set the operator (or / and) as the implicit operation.wildcard
options, accepts a boolean, in case of True, a new rule to identify wildcards will be addedOne the options are set, create a parser and pass the options as argument
parser = QPLParser(options=options)
With the parser created, parse the query with the line bellow
qpl_query = parser.parse_query('This is PyQPL')
The qpl_query will be an object of type Operator, which will contain all the operators of the query. At this point the qpl query is truly engine agnostic, and it needs a translator to be an engine query