Skip to content

Implement code expander #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Sep 17, 2020
Merged

Conversation

manta1130
Copy link
Contributor

@manta1130 manta1130 commented Sep 14, 2020

Closes #9
Closes #34

I have developed a script to combine the code into a single file at submission.

Usage

  • Import dsu

./expand.py dsu

  • Import dsu,fenwicktree

./expand.py dsu fenwicktree

  • Import convolution,internal_bit,modint,internal_math,internal_type_traits(Recursively resolving dependency)

./expand.py convolution

- Import dsu with comments

./expand.py --output-comment dsu

Problems

I removed the process to erase comments and test codes.
These problems were resolved.
- Removing test code
It removes the test code by looking for #[cfg(test)] on the source code and not reading after it in this implement.
Therefore,if another code exists below the test code, it will disappear.

- Removing comment
It simply looks for the // and delete the comment by not loading that line.
It can't remove multiple line comments(using /* ... */).

@qryxip
Copy link
Member

qryxip commented Sep 14, 2020

Do you think the "problems" should be resolved in the future? They seem to be hard to resolve with naive text-processing.

Just to be sure, could you list pros & cons of text searching in Python and token parsing in Rust that you think?

@manta1130
Copy link
Contributor Author

manta1130 commented Sep 15, 2020

@qryxip

Do you think the "problems" should be resolved in the future? They seem to be hard to resolve with naive text-processing.

I think it's hard to solve the problem with a simple implement.
The process to erase comments and test codes is not important, I'm considering remove it.
I think this would obviously impose some weird constraints on the writer of the code if it's not change this script.
(e.g. The test code has to be written at the bottom of the file.)

Just to be sure, could you list pros & cons of text searching in Python and token parsing in Rust that you think?

I think the following.

Advantages of this script:

  • It works with a single file.

  • It can select import modules.

Disadvantages of this script:

  • The dependencies of the module have to be described in the script.

@manta1130 manta1130 marked this pull request as ready for review September 15, 2020 12:06
@qryxip
Copy link
Member

qryxip commented Sep 15, 2020

Here are advantages/disadvantages of Rust implementation that I thought.

  1. Advantages
    1.1. In Rust, we can use proc-macro(2) and syn. That means we can easily add features in a robust way such as removing #[cfg(test)] items without imposing extra constraints.
    1.2. Written in Rust, we can provide a standalone binary that users can use without git clone, though we'd able to run Python script in it like Command::new("python").args(["-c", include_str!("../path/to/expand.py")]).
    $ cargo install ac-library-rs
    $ ac-library-rs convolution >> ./src/bin/a.rs
  2. Disadvantages
    2.1. The dependencies of the each module have to be explicitly described, too. Or rather, detecting dependencies is too hard by itself.
    2.2. It needs to be build. The CI will take about 60s longer.
    2.3. Larger than Python single file.

By the way, does "It works with a single file" mean "small, so it's easy to maintain"? If so, I agree with it.

Anyway, without the "removing docs & tests" function, I think that script is reasonable to Rust implementation.

Copy link
Member

@qryxip qryxip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not apply Rustfmt with subprocess.run(..)?

@qryxip qryxip requested a review from matsu7874 September 15, 2020 12:46
@manta1130
Copy link
Contributor Author

I added the process of rustfmt.

@manta1130 manta1130 requested a review from qryxip September 16, 2020 12:22
Co-authored-by: Ryo Yamashita <[email protected]>
@qryxip qryxip removed the request for review from matsu7874 September 17, 2020 16:25
@qryxip qryxip merged commit ee0d3df into rust-lang-ja:master Sep 17, 2020
@manta1130 manta1130 deleted the code-expander branch September 19, 2020 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a tool that exports the library as a single .rs file How to "expand" this crate
2 participants