Skip to content

Commit d0bac13

Browse files
committed
Add type stubs
1 parent 2527428 commit d0bac13

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"Topic :: Software Development :: Compilers",
3030
"Topic :: Text Processing :: Linguistic",
3131
],
32+
package_data={
33+
"tree_sitter": ["__init__.pyi"],
34+
},
3235
packages=["tree_sitter"],
3336
ext_modules=[
3437
Extension(

tree_sitter/__init__.pyi

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from typing import Optional, List, Iterator
2+
3+
4+
class Language:
5+
def __init__(self, path: str, name: str): ...
6+
7+
def field_id_for_name(self, name: str) -> int: ...
8+
def query(self, source) -> Query: ...
9+
10+
11+
class Parser:
12+
def set_language(self, lang: Language) -> None: ...
13+
def parse(self, src: bytes) -> Tree: ...
14+
15+
16+
class Node:
17+
type: str
18+
is_named: bool
19+
is_missing: bool
20+
has_changes: bool
21+
has_error: bool
22+
start_byte: int
23+
end_byte: int
24+
start_point: Point
25+
end_point: Point
26+
children: List[Node]
27+
child_count: int
28+
named_child_count: int
29+
next_sibling: Optional[Node]
30+
prev_sibling: Optional[Node]
31+
next_named_sibling: Optional[Node]
32+
prev_named_sibling: Optional[Node]
33+
parent: Optional[Node]
34+
35+
def walk(self) -> TreeCursor: ...
36+
def sexp(self) -> str: ...
37+
def child_by_field_id(self, id: int) -> Optional[Node]: ...
38+
def child_by_field_name(self, name: str) -> Optional[Node]: ...
39+
def children_by_field_id(self, id: int) -> Iterator[Node]: ...
40+
def children_by_field_name(self, name: str) -> Iterator[Node]: ...
41+
42+
43+
class Tree:
44+
root_node: Node
45+
walk(self): TreeCursor
46+
47+
48+
class TreeCursor:
49+
node: Node
50+
51+
def current_field_name(self) -> str: ...
52+
def goto_parent(self) -> bool: ...
53+
def goto_first_child(self) -> bool: ...
54+
def goto_next_sibling(self) -> bool: ...
55+
56+
57+
class Query:
58+
def captures(self, node: Node) -> List[Tuple[Node, str]]

0 commit comments

Comments
 (0)