Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 6607959

Browse files
committed
Adds way of loading context back to python
Signed-off-by: ncordon <nacho.cordon.castillo@gmail.com>
1 parent f4ddc55 commit 6607959

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

bblfsh/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from bblfsh.tree_order import TreeOrder
44
from bblfsh.aliases import *
55
from bblfsh.roles import role_id, role_name
6+
from bblfsh.context import context

bblfsh/context.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from bblfsh.aliases import ParseResponse
2+
from bblfsh.pyuast import decode, iterator, uast
3+
from bblfsh.tree_order import TreeOrder
4+
5+
# Python context
6+
class Context:
7+
def __init__(self, root: dict) -> None:
8+
self.ctx = uast()
9+
self.root = root
10+
11+
def filter(self, query: str) -> dict:
12+
return self.ctx.filter(query, self.root)
13+
14+
def iterate(self, order: int) -> iterator:
15+
TreeOrder.check_order(order)
16+
return iterator(self.root, order)
17+
18+
def context(root: dict) -> Context:
19+
return Context(root)

bblfsh/pyuast.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,6 @@ static PyObject *PythonContext_new(PyObject *self, PyObject *args) {
10661066
// TODO: optionally accept root object
10671067
if (!PyArg_ParseTuple(args, "")) return nullptr;
10681068

1069-
10701069
PythonContext *pyU = PyObject_New(PythonContext, &PythonContextType);
10711070
if (!pyU) return nullptr;
10721071

0 commit comments

Comments
 (0)