Add build scripts for C# and

unify the coding style.
This commit is contained in:
krahets
2023-02-08 22:18:02 +08:00
parent 38751cc5f5
commit 6dc21691ed
63 changed files with 2703 additions and 3911 deletions

View File

@ -15,6 +15,7 @@ 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
from docs.utils.extract_code_csharp import ExtractCodeBlocksCSharp
def build_markdown(md_path):
@ -42,8 +43,12 @@ def build_markdown(md_path):
extractor = extractor_dict[lang]
# Get code blocks
if file_name not in code_blocks_dict:
code_blocks_dict[file_name] = extractor.extract(
code_blocks = extractor.extract(
file_path=osp.dirname(md_path).replace("docs/", f"codes/{lang}/") + f"/{file_name}")
if code_blocks is None:
i += 1
continue
code_blocks_dict[file_name] = code_blocks
header_line = i
class_label = src_match[1]
@ -90,6 +95,7 @@ extractor_dict = {
"javascript": ExtractCodeBlocksJSTS(),
"typescript": ExtractCodeBlocksJSTS(),
"swift": ExtractCodeBlocksSwift(),
"csharp": ExtractCodeBlocksCSharp(),
}

View File

@ -1,14 +1,27 @@
# This script is borrowed from https://gist.github.com/cobyism/4730490
python docs/utils/build_markdown.py
while true; do
read -p "Do you wish to deploy the site? [y] [n]" yn
case $yn in
[Yy]* ) make install; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes[y] or no[n].";;
esac
done
# push the built docs
cd build
git add .
git commit -m "build"
git push -u origin docs
cd ..
# Build mkdocs
mkdocs build --clean
# deploy the site
cd site
git add .
git commit -m "deploy"
git push -u origin gh-pages
cd..

View File

@ -0,0 +1,28 @@
"""
File: extract_code_csharp.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 ExtractCodeBlocksCSharp(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*(|\S+)\s*(\w+)(\(.*\))'
self.class_pattern = r'(public|)\s*(class|struct)\s+(\w+)\s*\n'
self.func_pattern_keys = ["total", "ind", "scope", "static", "return", "label", "args"]
self.class_pattern_keys = ["total", "scope", "type", "label"]
# for code_path in glob.glob("codes/csharp/chapter_*/array.cs"):
# ext = ExtractCodeBlocksCSharp()
# res = ext.extract(code_path)
# pass

View File

@ -31,6 +31,9 @@ class ExtractCodeBlocksJava:
"""
Extract classes and functions from a markdown document
"""
if not osp.isfile(file_path):
return None
self.file_path = file_path
with open(file_path) as f:
self.lines = f.readlines()

View File

@ -21,8 +21,3 @@ class ExtractCodeBlocksJSTS(ExtractCodeBlocksJava):
self.func_pattern_keys = ["total", "ind", "prefix", "label", ":", "return"]
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)

View File

@ -49,7 +49,3 @@ class ExtractCodeBlocksPython(ExtractCodeBlocksJava):
remove_empty_lines(func)
for func in funcs.values():
remove_empty_lines(func)
# ext = ExtractCodeBlocksPython()
# ext.extract("codes/python/chapter_array_and_linkedlist/my_list.py")

View File

@ -21,8 +21,3 @@ class ExtractCodeBlocksSwift(ExtractCodeBlocksJava):
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)