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

Make CLI format format #1459

Merged
merged 3 commits into from
Aug 26, 2023
Merged

Make CLI format format #1459

merged 3 commits into from
Aug 26, 2023

Conversation

xsebek
Copy link
Member

@xsebek xsebek commented Aug 23, 2023

app/Main.hs Outdated Show resolved Hide resolved
@xsebek
Copy link
Member Author

xsebek commented Aug 24, 2023

@byorgey once #1464 lands, this could be good to go:

> cabal run swarm -O0 -- format scenarios/Challenges/_blender/patrol-clockwise.sw
def forever = \c. c; forever c end;
def encircle = \lDir. \rDir.
  turn lDir;
  b <- blocked;
  if b {turn rDir} {wait 1};
  fwBlocked <- blocked;
  if fwBlocked {turn rDir} {move}
end;
def patrolCW = forever (encircle right left) end;
patrolCW

I noticed it drops comments, but we can fix that later.

@byorgey
Copy link
Member

byorgey commented Aug 24, 2023

Oh, right. Preserving comments will be trickier since right now we just treat them as whitespace and throw them away.

https://www.reddit.com/r/haskell/comments/ni4gpm/how_to_retrieve_comments_using_megaparsec/?rdt=59638 is relevant.

mergify bot pushed a commit that referenced this pull request Aug 25, 2023
- improve layout of terms:
  - break lines on binds, unless it fits on one line
  - lambdas go on same line, but the body _can_ go to next line
  - def and let can have long body on next line (indented for def)
  - parens and braces have body indented if it does not fit on line
- closes #11

Example using `--format` from #1459:

```
> cabal run swarm -O0 -- format scenarios/Challenges/_blender/patrol-clockwise.sw                          
def forever = \c. c; force forever c end;
def encircle = \lDir. \rDir.
  turn lDir;
  b <- blocked;
  if b {turn rDir} {wait 1};
  fwBlocked <- blocked;
  if fwBlocked {turn rDir} {move}
end;
def patrolCW = force forever (force encircle right left) end;
force patrolCW
```
@xsebek
Copy link
Member Author

xsebek commented Aug 26, 2023

Rebased and ready to go! 🙂

@xsebek xsebek added merge me Trigger the merge process of the Pull request. CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. labels Aug 26, 2023
mergify bot pushed a commit that referenced this pull request Aug 26, 2023
- give lambdas lower precedence (9) then application (10)
- closes #1468

Before (with #1459):
```
❯ cabal run swarm -O0 -- format <(echo '\\m. case m (\\x. x + 1) (\\y. y * 2)')
\m. case m \x. x + 1 \y. y * 2
```

After:
```
❯ cabal run swarm -O0 -- format <(echo '\\m. case m (\\x. x + 1) (\\y. y * 2)')
\m. case m (\x. x + 1) (\y. y * 2)
```
@mergify mergify bot merged commit 09f8aee into main Aug 26, 2023
9 checks passed
@mergify mergify bot deleted the format-for-real branch August 26, 2023 17:47
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.

format subcommand is a misnomer
2 participants