Fixed #68: Implement SheerkaQL
Fixed #70: SheerkaFilterManager : Pipe functions Fixed #71: SheerkaFilterManager : filter_objects Fixed #75: SheerkaMemory: Enhance memory() to use the filtering capabilities Fixed #76: SheerkaEvaluateConcept: Concepts that modify the state of the system must not be evaluated during question
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user