from sheerkaql.lexer import Lexer from sheerkaql.parser import Parser lexer_instance = Lexer() class SheerkaQueryLanguage: def compile(self, query): """ Compiles a query string into a python function that takes one parameter, the execution namespace. The compiled function is re-usable. For information on the grammar see X. """ return Parser().parse(bytes(query, 'utf-8').decode('unicode_escape'), lexer=lexer_instance) def execute(self, query, namespace, allow_builtins=False): """" Compiles the query string and executes it with the supplied namespace. If you want to execute a particular query many times, use compile to get a query function. :param query: query to execute (from self.compile()) :param namespace: execution's namespace :param allow_builtins: auto add builtin functions and names """ if allow_builtins: namespace.update(__builtins__) return self.compile(query)(namespace)