Skip to content
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

Add format --v0.5 option to port code from older syntax #1851

Merged
merged 5 commits into from
May 22, 2024

Conversation

byorgey
Copy link
Member

@byorgey byorgey commented May 15, 2024

This is a followup on top of #1583 which turns swarm format into a tool for porting existing Swarm code into the newest syntax, via an extra --v0.5 argument. In particular, this PR:

  • Generalizes the parser to take a configuration record, which among other things contains the language version being parsed.
  • Adds code to allow the parser to parse either the current syntax or one version ago (when types did not start with capital letter) depending on the version in the configuration.
    • The idea is to have the parser always support the current version and one older version, so we can always upgrade version n to version n+1.
  • Adds a new flag --v0.5 to the format subcommand which causes the input to be parsed in v0.5 mode. However, the output of format will always use the latest syntax. Thus, swarm format --v0.5 reads code in v0.5 format and prints it in the latest format, so this can be used to automatically port existing .sw files.

This PR also makes a few minor improvements to pretty-printing.

@byorgey byorgey requested a review from kostmo May 15, 2024 20:59
@byorgey byorgey added the CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. label May 16, 2024
Copy link
Member

@kostmo kostmo left a comment

Choose a reason for hiding this comment

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

Looks like this PR is a superset of #1583? For reviewability, the base branch should be set to feature/uppercase-types so we don't review the same subset of changes twice.

@byorgey
Copy link
Member Author

byorgey commented May 21, 2024

For reviewability, the base branch should be set to feature/uppercase-types so we don't review the same subset of changes twice.

Oh, that makes sense, thanks, that's what I was missing. I guess I haven't done stacked PRs that much and I wasn't sure how to do it.

byorgey added 4 commits May 21, 2024 18:49
- Generalize the parser to take a configuration record
- Add to the configuration the current language version being parsed
- Add code to allow the parser to parse either the current
  syntax or one version ago (when types did not start with capital
  letter) depending on the version in the configuration
- Add option `--v0.5` to the `format` subcommand to parse v0.5 code.
  However, the output will always be in the latest format, so this
  can be used to automatically upgrade existing `.sw` files.
- Print `{noop}` as `{}`
- Print blank line between consecutive `def`s instead of a semicolon
Co-authored-by: Restyled.io <commits@restyled.io>
@byorgey byorgey added the merge me Trigger the merge process of the Pull request. label May 21, 2024
@mergify mergify bot merged commit e071252 into main May 22, 2024
11 checks passed
@mergify mergify bot deleted the feature/format-conversion branch May 22, 2024 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants