From 63db196bf99797ac198b26c2714581c4827cf1d0 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 5 May 2024 12:05:41 +0800 Subject: [PATCH] add references --- .github/workflows/website.yml | 1 + .gitignore | 2 ++ include/pocketpy/vm.h | 2 +- scripts/build_references.py | 40 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 scripts/build_references.py diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 6e2d9877..496207f3 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -29,6 +29,7 @@ jobs: actions-cache-folder: 'emsdk-cache' - name: Compile run: | + python scripts/build_references.py bash build_web.sh mv web docs/.retype/static ################################################### diff --git a/.gitignore b/.gitignore index dec9592a..ebacf3f3 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ main pocketpy.dSYM libpocketpy.dylib.dSYM/ main.dSYM/ + +docs/references.md \ No newline at end of file diff --git a/include/pocketpy/vm.h b/include/pocketpy/vm.h index 9c4405f3..a25ea4cb 100644 --- a/include/pocketpy/vm.h +++ b/include/pocketpy/vm.h @@ -380,6 +380,7 @@ public: PyObject* new_user_object(Args&&... args){ return heap.gcnew(_tp_user(), std::forward(args)...); } +#endif template Type _find_type_in_cxx_typeid_map(){ @@ -395,7 +396,6 @@ public: } return it->second; } -#endif /********** private **********/ virtual ~VM(); diff --git a/scripts/build_references.py b/scripts/build_references.py new file mode 100644 index 00000000..e2743df5 --- /dev/null +++ b/scripts/build_references.py @@ -0,0 +1,40 @@ +import re + +filepath = 'include/pocketpy/vm.h' + +with open(filepath, 'r', encoding='utf-8') as f: + lines = f.readlines() + +REGION_PATTERN = re.compile(r'#if PK_REGION\("(.+)"\)') + +current_region = None +output = [] + +def parse_line(line: str): + output.append(line) + +for line in lines: + if current_region: + if line.startswith('#endif'): + current_region = None + output.append('```\n\n') + else: + parse_line(line.strip(' ')) + else: + m = REGION_PATTERN.match(line) + if m: + current_region = m.group(1) + output.append(f'### {current_region}\n') + output.append('```cpp\n') + +with open('docs/references.md', 'w', encoding='utf-8') as f: + f.write('''---label: References +icon: code +order: 2 +--- + +''') + content = ''.join(output) + # replace {...} to ; (multi-line match) + content = re.sub(r'{(.+?)}', r';', content, flags=re.DOTALL) + f.write(content)