tree-sitter-omega
aien-dev/tree-sitter-omega
Brought by drakestapleton
tree-sitter-omega / bindings / python / tree_sitter_omega / __init__.py
| 1 | """Omega (.om, Omegese) grammar for tree-sitter""" |
| 2 | |
| 3 | from ._binding import language |
| 4 | |
| 5 | |
| 6 | def _get_query(name, file): |
| 7 | files = globals().get("_files") |
| 8 | if files is None: |
| 9 | from importlib.resources import files |
| 10 | globals()["_files"] = files |
| 11 | try: |
| 12 | query = files(f"{__package__}") / file |
| 13 | globals()[name] = query.read_text() |
| 14 | except FileNotFoundError: |
| 15 | globals()[name] = None |
| 16 | return globals()[name] |
| 17 | |
| 18 | |
| 19 | def __getattr__(name): |
| 20 | if name == "HIGHLIGHTS_QUERY": |
| 21 | return _get_query("HIGHLIGHTS_QUERY", "queries/highlights.scm") |
| 22 | if name == "INJECTIONS_QUERY": |
| 23 | return _get_query("INJECTIONS_QUERY", "queries/injections.scm") |
| 24 | if name == "LOCALS_QUERY": |
| 25 | return _get_query("LOCALS_QUERY", "queries/locals.scm") |
| 26 | if name == "TAGS_QUERY": |
| 27 | return _get_query("TAGS_QUERY", "queries/tags.scm") |
| 28 | |
| 29 | raise AttributeError(f"module {__name__!r} has no attribute {name!r}") |
| 30 | |
| 31 | |
| 32 | __all__ = [ |
| 33 | "language", |
| 34 | "HIGHLIGHTS_QUERY", |
| 35 | "INJECTIONS_QUERY", |
| 36 | "LOCALS_QUERY", |
| 37 | "TAGS_QUERY", |
| 38 | ] |
| 39 | |
| 40 | |
| 41 | def __dir__(): |
| 42 | return sorted(__all__ + [ |
| 43 | "__all__", "__builtins__", "__cached__", "__doc__", "__file__", |
| 44 | "__loader__", "__name__", "__package__", "__path__", "__spec__", |
| 45 | ]) |