2023-02-08 04:27:55 +08:00
|
|
|
"""
|
|
|
|
File: extract_code_python.py
|
|
|
|
Created Time: 2023-02-07
|
|
|
|
Author: Krahets (krahets@163.com)
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import glob
|
|
|
|
import sys, os.path as osp
|
|
|
|
sys.path.append(osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__)))))
|
|
|
|
from docs.utils.extract_code_java import ExtractCodeBlocksJava
|
|
|
|
|
|
|
|
|
|
|
|
class ExtractCodeBlocksJSTS(ExtractCodeBlocksJava):
|
|
|
|
def __init__(self) -> None:
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
# Pattern to match function names and class names
|
2023-02-08 19:45:06 +08:00
|
|
|
self.func_pattern = r'(\s*)(function|private|public|)\s*(\S*)\(.*\)(:|)\s*(.*)\s+{\s*\n'
|
2023-02-08 04:27:55 +08:00
|
|
|
self.class_pattern = r'class\s+(\w+)\s*\{'
|
|
|
|
|
2023-02-08 19:45:06 +08:00
|
|
|
self.func_pattern_keys = ["total", "ind", "prefix", "label", ":", "return"]
|
2023-02-08 04:27:55 +08:00
|
|
|
self.class_pattern_keys = ["total", "label"]
|
|
|
|
|
|
|
|
|
|
|
|
# for code_path in glob.glob("codes/cpp/chapter_*/my_heap.cpp"):
|
|
|
|
# ext = ExtractCodeBlocksCpp()
|
|
|
|
# ext.extract(code_path)
|