Skip to content

Commit e217654

Browse files
committed
Add support for languages with a dash in its name
1 parent aace8cf commit e217654

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

code_ast/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def code(self):
3333
def __repr__(self):
3434

3535
lang = self.config.lang
36-
lang_name = lang[0].upper() + lang[1:]
36+
lang_name = "".join((lang_part[0].upper() + lang_part[1:] for lang_part in lang.split("-")))
3737

3838
ast_repr = ast_to_str(self.source_tree, indent = 1)
3939

code_ast/parsers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def load_language(lang):
5050
source_lang_path = os.path.join(cache_path, "tree-sitter-%s" % lang)
5151

5252
if os.path.isfile(compiled_lang_path):
53-
return Language(compiled_lang_path, lang)
53+
return Language(compiled_lang_path, _lang_to_fnname(lang))
5454

5555
if os.path.exists(source_lang_path) and os.path.isdir(source_lang_path):
5656
logger.warn("Compiling language for %s" % lang)
@@ -196,6 +196,14 @@ def _compile_lang(source_path, compiled_path):
196196
)
197197

198198

199+
def _lang_to_fnname(lang):
200+
"""
201+
dash is not supported for function names. Therefore,
202+
we assume that dashes represented by underscores.
203+
"""
204+
return lang.replace("-", "_")
205+
206+
199207
# Auto Clone from Github --------------------------------
200208

201209
def _exists_url(url):

0 commit comments

Comments
 (0)