You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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

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)
  • The 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.
  • The wildcard options, accepts a boolean, in case of True, a new rule to identify wildcards will be added


One 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

  • No labels