Skip to content

Commit ea08aa2

Browse files
authored
Merge pull request #37 from aboutcode-org/add-cython
Add Cython to TS_LANGUAGE_WHEELS
2 parents bbf5c4d + 91d02f6 commit ea08aa2

5 files changed

Lines changed: 2484 additions & 8 deletions

File tree

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
vNext
5+
-----
6+
7+
- Add support for Cython
8+
- Add the function ``source_inspector.symbols_tree_sitter.get_tree_and_language_info``
9+
410
v0.6.1
511
------
612

src/source_inspector/symbols_tree_sitter.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,34 @@ def get_treesitter_symbols(location, **kwargs):
8989
)
9090

9191

92-
def collect_symbols_and_strings(location):
93-
"""
94-
Return lists containing mappings of symbols and strings collected from file at location.
92+
def get_tree_and_language_info(location):
9593
"""
96-
symbols, strings = [], []
94+
Given the `location` of a file, determine the correct parser to use, parse
95+
the file, and return a tuple of (`tree`, `language_info`).
9796
97+
Return (None, None) if a parser is not found for the file type at `location`
98+
"""
99+
tree = None
100+
language_info = None
98101
if parser_result := get_parser(location):
99102
parser, language_info = parser_result
100103

101104
with open(location, "rb") as f:
102105
source = f.read()
103106

104107
tree = parser.parse(source)
108+
return tree, language_info
109+
return tree, language_info
110+
111+
112+
def collect_symbols_and_strings(location):
113+
"""
114+
Return lists containing mappings of symbols and strings collected from file at location.
115+
"""
116+
symbols, strings = [], []
117+
118+
tree, language_info = get_tree_and_language_info(location)
119+
if tree and language_info:
105120
traverse(tree.root_node, symbols, strings, language_info)
106121

107122
return symbols, strings
@@ -165,6 +180,11 @@ def traverse(node, symbols, strings, language_info):
165180
"identifiers": ["identifier"],
166181
"string_literals": ["string_literal"],
167182
},
183+
"Cython": {
184+
"wheel": "tree_sitter_python",
185+
"identifiers": ["identifier"],
186+
"string_literals": ["string_literal"],
187+
},
168188
"Go": {
169189
"wheel": "tree_sitter_go",
170190
"identifiers": ["identifier"],

0 commit comments

Comments
 (0)