Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
anpl4mc
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ziyuan Nan
anpl4mc
Commits
0738414d
Commit
0738414d
authored
Oct 17, 2023
by
nzy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add merge
parent
6b738550
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
5 deletions
+22
-5
anplc.py
+22
-5
No files found.
anplc.py
View file @
0738414d
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment