From bdacdc4cb464fe1d43875dc4cdad1ad5a86e39f9 Mon Sep 17 00:00:00 2001 From: nmd2000 Date: Thu, 17 Aug 2023 17:51:58 +0700 Subject: [PATCH] release 008 --- HISTORY.md | 10 ++++++++++ pyproject.toml | 2 +- src/codetext/codetext_cli.py | 9 ++++++++- src/codetext/parser/java_parser.py | 4 ++++ src/codetext/utils/utils.py | 7 +++++-- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index b84a5c6..7ca2548 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 8f39ea2..d8bb24d 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -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="dungnm.workspace@gmail.com" }, ] diff --git a/src/codetext/codetext_cli.py b/src/codetext/codetext_cli.py index 91f7fd9..36e25ba 100644 --- a/src/codetext/codetext_cli.py +++ b/src/codetext/codetext_cli.py @@ -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 @@ -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"]): @@ -116,6 +118,11 @@ def print_result(res: Dict, file_name: str = "no_name_file"): if i <= 1 and method["return_type"] != "" 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] diff --git a/src/codetext/parser/java_parser.py b/src/codetext/parser/java_parser.py index 2046e11..9be34b6 100644 --- a/src/codetext/parser/java_parser.py +++ b/src/codetext/parser/java_parser.py @@ -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: diff --git a/src/codetext/utils/utils.py b/src/codetext/utils/utils.py index c3d809f..d330ecb 100644 --- a/src/codetext/utils/utils.py +++ b/src/codetext/utils/utils.py @@ -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