mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-24 02:03:10 +08:00
Add build script for Swift.
This commit is contained in:
@ -14,6 +14,7 @@ from docs.utils.extract_code_python import ExtractCodeBlocksPython
|
||||
from docs.utils.extract_code_java import ExtractCodeBlocksJava
|
||||
from docs.utils.extract_code_cpp import ExtractCodeBlocksCpp
|
||||
from docs.utils.extract_code_jsts import ExtractCodeBlocksJSTS
|
||||
from docs.utils.extract_code_swift import ExtractCodeBlocksSwift
|
||||
|
||||
|
||||
def build_markdown(md_path):
|
||||
@ -88,6 +89,7 @@ extractor_dict = {
|
||||
"cpp": ExtractCodeBlocksCpp(),
|
||||
"javascript": ExtractCodeBlocksJSTS(),
|
||||
"typescript": ExtractCodeBlocksJSTS(),
|
||||
"swift": ExtractCodeBlocksSwift(),
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""
|
||||
File: extract_code_python.py
|
||||
File: extract_code_cpp.py
|
||||
Created Time: 2023-02-07
|
||||
Author: Krahets (krahets@163.com)
|
||||
"""
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""
|
||||
File: extract_code_python.py
|
||||
File: extract_code_java.py
|
||||
Created Time: 2023-02-07
|
||||
Author: Krahets (krahets@163.com)
|
||||
"""
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""
|
||||
File: extract_code_python.py
|
||||
File: extract_code_jsts.py
|
||||
Created Time: 2023-02-07
|
||||
Author: Krahets (krahets@163.com)
|
||||
"""
|
||||
@ -17,10 +17,10 @@ class ExtractCodeBlocksJSTS(ExtractCodeBlocksJava):
|
||||
|
||||
# Pattern to match function names and class names
|
||||
self.func_pattern = r'(\s*)(function|private|public|)\s*(\S*)\(.*\)(:|)\s*(.*)\s+{\s*\n'
|
||||
self.class_pattern = r'class\s+(\w+)\s*\{'
|
||||
self.class_pattern = r'(public|)\s*class\s+(\w+)\s*\{'
|
||||
|
||||
self.func_pattern_keys = ["total", "ind", "prefix", "label", ":", "return"]
|
||||
self.class_pattern_keys = ["total", "label"]
|
||||
self.class_pattern_keys = ["total", "scope", "label"]
|
||||
|
||||
|
||||
# for code_path in glob.glob("codes/cpp/chapter_*/my_heap.cpp"):
|
||||
|
28
docs/utils/extract_code_swift.py
Normal file
28
docs/utils/extract_code_swift.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""
|
||||
File: extract_code_swift.py
|
||||
Created Time: 2023-02-08
|
||||
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 ExtractCodeBlocksSwift(ExtractCodeBlocksJava):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
# Pattern to match function names and class names
|
||||
self.func_pattern = r'(\s*)(public|private|)\s*(static|)\s*(func|)\s*(\w+)\(.*\).+{\s*\n'
|
||||
self.class_pattern = r'(public|)\s*class\s+(\w+)\s*\{'
|
||||
|
||||
self.func_pattern_keys = ["total", "ind", "scope", "static", "func", "label"]
|
||||
self.class_pattern_keys = ["total", "scope", "label"]
|
||||
|
||||
|
||||
# for code_path in glob.glob("codes/cpp/chapter_*/my_heap.cpp"):
|
||||
# ext = ExtractCodeBlocksCpp()
|
||||
# ext.extract(code_path)
|
Reference in New Issue
Block a user