Page MenuHomeSoftware Heritage
Paste P1092

py-tree-sitter/swh_ql
ActivePublic

Authored by KShivendu on Jul 9 2021, 11:19 AM.
from tree_sitter import Language, Parser
Language.build_library(
'build/swh-query-language.so',
['.']
)
SWH_QL = Language('build/swh-query-language.so', 'swh_search_query_language')
parser = Parser()
parser.set_language(SWH_QL)
def _dfs(node, level = 0):
if node is None:
return
print( level * '\t', node, level)
if node.has_error or node.is_missing:
print(node.sexp())
# print(node.__dir__())
for child in node.children:
_dfs(child, level + 1)
INPUT = """with_visi """
tree = parser.parse(bytes(INPUT, "utf8"))
root_node = tree.root_node
print("INPUT: ")
print(INPUT)
sexp = root_node.sexp()
print("SEXP: ")
print(sexp)
print("DFS:")
_dfs(root_node)
if sexp == "(query)":
print("Please enter something")
['__repr__', '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', 'walk', 'sexp', 'child_by_field_id', 'child_by_field_name', 'type', 'is_named', 'is_missing', 'has_changes', 'has_error', 'start_byte', 'end_byte', 'start_point', 'end_point', 'children', 'child_count', 'named_child_count', 'next_sibling', 'prev_sibling', 'next_named_sibling', 'prev_named_sibling', 'parent', '__doc__', '__hash__', '__str__', '__getattribute__', '__setattr__', '__delattr__', '__init__', '__new__', '__reduce_ex__', '__reduce__', '__subclasshook__', '__init_subclass__', '__format__', '__sizeof__', '__dir__', '__class__']

Event Timeline

KShivendu created this object in space S1 Public.