Commit 0738414d by nzy

add merge

parent 6b738550
......@@ -39,14 +39,16 @@ def input_content(content):
return content
require_pattern = r"const \{ ([^}]+) \} = require\('\.\/\1\.js'\);"
exports_pattern = r"exports\.(?P<hole2>[a-zA-Z_]\w*) = \1;\s*"
exports_pattern = r"exports\.(?P<hole>[a-zA-Z_]\w*) = \1;\s*"
def remove_dependencies(code):
code = re.sub(require_pattern, '', code)
code = re.sub(exports_pattern, '', code)
return code.strip()
def sketch(fun_name):
if (path := fun_lib / f"{fun_name}.js").exists():
with open(path, "r") as f:
raw_content = f.read()
content = re.sub(require_pattern, '', raw_content)
content = re.sub(exports_pattern, '', content)
content = content.strip()
content = remove_dependencies(f.read())
else:
content = sketch_template(fun_name)
code = input_content(content)
......@@ -56,6 +58,16 @@ def hole(fun_name):
doc = input_content(doc_template(fun_name))
create_dest(fun_name, doc)
def merge(fun_name):
codes = []
js_files = [file for file in fun_lib.glob('*.js') if not file.name.startswith('.')]
for file in js_files:
with open(file, "r") as f:
codes.append(remove_dependencies(f.read()))
codes.append(f"await {fun_name}(bot);")
with open(f"full_{fun_name}.js", "w") as f:
f.write("\n".join(codes))
async def main():
parser = argparse.ArgumentParser(description="A script for anplc.")
subparsers = parser.add_subparsers(dest="command")
......@@ -70,6 +82,9 @@ async def main():
syn_parser.add_argument('fun_name', nargs='?', default=None, help="Name of the function to synthesis.")
syn_parser.add_argument('--all', action='store_true', help="Compile all functions.")
syn_parser.add_argument('--sketch', default=None, help="Name of the sketch to synthesis.")
merge_parser = subparsers.add_parser('merge')
merge_parser.add_argument('fun_name', nargs='?', default=None, help="Name of the funtion to merge.")
args = parser.parse_args()
if args.command == "sketch":
......@@ -95,6 +110,8 @@ async def main():
await synthesis_1(args.fun_name)
elif args.sketch:
await synthesis_1_inorder(args.sketch)
elif args.command == "merge":
merge(args.fun_name)
else:
parser.print_help()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment