Skip to content

Commit

Permalink
release 008
Browse files Browse the repository at this point in the history
  • Loading branch information
nmd2k committed Aug 17, 2023
1 parent 833683a commit bdacdc4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
10 changes: 10 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,13 @@ Release data: Jul 5, 2023
* Update all class extractor format (using dict instead of list)
* Fix missing identifier, parameter in C, C#, Java parser
* Implement CLI

Version 0.0.8
=============
Release data: Aug 17, 2023

* Update format codetext_cli
* Update PythonParser: Handle class definitions with empty argument list class ABC()
* Add Javascript undeclared functions
* Add PHP interface
* Add Ruby actions with block parameters
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "codetext"
version = "0.0.7"
version = "0.0.8"
authors = [
{ name="Dung Manh Nguyen", email="[email protected]" },
]
Expand Down
9 changes: 8 additions & 1 deletion src/codetext/codetext_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def parse_file(file_path: str, language: str = None, verbose: bool = False) -> L
method_list = parser.get_function_list(_cls)
for method in method_list:
method_info = parser.get_function_metadata(method)
method_info['code'] = get_node_text(method)
cls_method.append(method_info)

cls_info["method"] = cls_method
Expand Down Expand Up @@ -88,7 +89,8 @@ def print_result(res: Dict, file_name: str = "no_name_file"):

# ========= Print class & method =========
cls_headers = ["#", "Class", "Arguments"]
cls_method_headers = ["#", "Method name", "Paramters", "Type", "Return type"]
cls_method_headers = ["#", "Method name", "Paramters",
"Type", "Return type", "Throws"]
cls_info = []
method_info = {}
for cls_idx, _cls in enumerate(res["class"]):
Expand Down Expand Up @@ -116,6 +118,11 @@ def print_result(res: Dict, file_name: str = "no_name_file"):
if i <= 1 and method["return_type"] != "<not_specific>"
else ""
)
sublist[5] = (
method["throws"]
if i <= 1 and "throws" in method.keys()
else ""
)
_method_info.append(sublist)

method_info[file_name] = [_cls["identifier"], _method_info]
Expand Down
4 changes: 4 additions & 0 deletions src/codetext/parser/java_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ def get_function_metadata(function_node, blob: str = None) -> Dict[str, str]:
metadata['identifier'] = get_node_text(child)
elif child.type in return_kinds:
metadata['return_type'] = get_node_text(child)
elif child.type == 'throws':
for subchild in child.children:
if 'identifier' in subchild.type:
metadata['throws'] = get_node_text(subchild)
elif child.type == 'formal_parameters':
param_list = get_node_by_kind(child, ['formal_parameter']) # speed_parameter
for param in param_list:
Expand Down
7 changes: 5 additions & 2 deletions src/codetext/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def parse_code(raw_code: str, language: str='Auto', tree_sitter_path: str=None)
parser.set_language(language)

if isinstance(raw_code, str):
tree = parser.parse(bytes(raw_code, 'utf8'))
return tree
raw_code = bytes(raw_code, 'utf8')
elif isinstance(raw_code, bytes):
pass
else:
raise ValueError(f"Expect `str`, got {type(raw_code)}")
tree = parser.parse(raw_code)
return tree

0 comments on commit bdacdc4

Please sign in to comment.