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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
a couple special cases to improve pretty-printing
- Print `{noop}` as `{}`
- Print blank line between consecutive `def`s instead of a semicolon
  • Loading branch information
byorgey committed May 21, 2024
commit 0b7e5ad09895b0770ff2a58024fc128c2b9cc53c
6 changes: 6 additions & 0 deletions src/swarm-lang/Swarm/Language/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ instance PrettyPrec (Term' ty) where
prettyPrec p (TRequire n e) = pparens (p > 10) $ "require" <+> pretty n <+> ppr @Term (TText e)
prettyPrec p (SRequirements _ e) = pparens (p > 10) $ "requirements" <+> ppr e
prettyPrec _ (TVar s) = pretty s
prettyPrec _ (SDelay _ (Syntax' _ (TConst Noop) _ _)) = "{}"
prettyPrec _ (SDelay _ t) = group . encloseWithIndent 2 lbrace rbrace $ ppr t
prettyPrec _ t@SPair {} = prettyTuple t
prettyPrec p t@(SLam {}) =
Expand Down Expand Up @@ -266,6 +267,11 @@ instance PrettyPrec (Term' ty) where
[ prettyDefinition "def" x mty t1
, "end"
]
-- Special case for printing consecutive defs: don't worry about
-- precedence, and print a blank line with no semicolon
prettyPrec _ (SBind Nothing t1@(Syntax' _ (SDef {}) _ _) t2) =
prettyPrec 0 t1 <> hardline <> hardline <> prettyPrec 0 t2
-- General case for bind
prettyPrec p (SBind Nothing t1 t2) =
pparens (p > 0) $
prettyPrec 1 t1 <> ";" <> line <> prettyPrec 0 t2
Expand Down