Skip to content

Commit

Permalink
fix formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed May 30, 2023
1 parent b147aa8 commit 124b1c9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/Juvix/Compiler/Concrete/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,10 @@ data Iterator s = Iterator
{ _iteratorName :: IdentifierType s,
_iteratorInitializers :: [Initializer s],
_iteratorRanges :: [Range s],
_iteratorBody :: ExpressionType s
_iteratorBody :: ExpressionType s,
-- | Due to limitations of the pretty printing algorithm, we store whether
-- the iterator was surrounded by parentheses in the code.
_iteratorParens :: Bool
}

deriving stock instance
Expand Down Expand Up @@ -1192,7 +1195,7 @@ expressionAtomicity e = case sing :: SStage s of
SScoped -> atomicity e

instance HasAtomicity (Iterator s) where
atomicity = const (Aggregate appFixity)
atomicity = const Atom

instance HasAtomicity (Case s) where
atomicity = const Atom
Expand Down
6 changes: 4 additions & 2 deletions src/Juvix/Compiler/Concrete/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,11 @@ instance (SingI s) => PrettyCode (Iterator s) where
is <- mapM ppCode _iteratorInitializers
rngs <- mapM ppCode _iteratorRanges
let is' = if null is then Nothing else Just (parens (hsep (punctuate semi is)))
rngs' = if null rngs then mempty else parens (hsep (punctuate semi rngs))
rngs' = if null rngs then Nothing else Just (parens (hsep (punctuate semi rngs)))
b <- ppExpression _iteratorBody
return $ hang' (n <+> is' <?+> rngs' <> oneLineOrNextNoIndent b)
return $
parensIf _iteratorParens $
hang' (n <+?> is' <+?> rngs' <> oneLineOrNextNoIndent b)

instance (SingI s) => PrettyCode (Initializer s) where
ppCode Initializer {..} = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,7 @@ checkIterator iter = do
rngpats' <- mapM checkParsePatternAtoms rngpats
let _iteratorInitializers = zipWithExact Initializer inipats' inivals'
_iteratorRanges = zipWithExact Range rngpats' rngvals'
_iteratorParens = iter ^. iteratorParens
_iteratorBody <- checkParseExpressionAtoms (iter ^. iteratorBody)
return Iterator {..}

Expand Down Expand Up @@ -1343,6 +1344,7 @@ checkParens e@(ExpressionAtoms as _) = case as of
scopedId <- checkName s
let scopedIdenNoFix = idenOverName (set S.nameFixity Nothing) scopedId
return (ExpressionParensIdentifier scopedIdenNoFix)
AtomIterator i :| [] -> ExpressionIterator . set iteratorParens True <$> checkIterator i
AtomCase c :| [] -> ExpressionCase . set caseParens True <$> checkCase c
_ -> checkParseExpressionAtoms e

Expand Down
1 change: 1 addition & 0 deletions src/Juvix/Compiler/Concrete/Translation/FromSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ iterator = do
rparen
return rngs
_iteratorBody <- parseExpressionAtoms
let _iteratorParens = False
return Iterator {..}
where
initializer :: ParsecS r (Initializer 'Parsed)
Expand Down
3 changes: 2 additions & 1 deletion tests/Compilation/positive/test054.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ main :=
sum lst
+ sum' lst
+ fst (for (a, b := 0, 0) (x in lst) b + x, a)
+ (for2 (acc := 0) (x in lst; y in 1 :: 2 :: nil) acc + x + y)
+ (for2 (acc := 0) (x in lst; y in 1 :: 2 :: nil)
acc + x + y)
+ fst
(myzip2 (a := 0; b := 0) (x in lst; y in reverse lst)
a + x * y, b + y)
Expand Down

0 comments on commit 124b1c9

Please sign in to comment.