git.iko.soy/rowtype-yoga/pose
on main help sign in
6
commit241817f557f016cabbc9a8cc1af8f2d64d139c4a authorMark Eibes <mark.eibes@gmail.com> dateSat 3 Jul 2021, 21:57 (5 years ago) parent0fea611
1 file changed+58−34
src/Format.purs+58−34
src/Format.purs+58−34
@@ -4,6 +4,7 @@ import Prelude
44
55import Data.Array (head)
66import Data.Array as Array
7+import Data.Array.NonEmpty (last)
78import Data.Array.NonEmpty as NE
89import Data.Foldable (fold, foldMap)
910import Data.Maybe (Maybe(..))
@@ -479,14 +480,15 @@ formatInstanceHead indentation indent''
479480 } = do
480481 let
481482 lines = rangeOfInstanceHead instanceHead
482− indentTrick = (indent'' <> indentation)
483483 (indent /\ indent' /\ prefix) = case lines of
484484 MultipleLines ->
485− (indentTrick <> indentation) /\ indentTrick /\ (newline <> indentTrick)
485+ (indent'' <> indentation <> indentation) /\
486+ (indent'' <> indentation) /\
487+ (newline <> indent'' <> indentation)
486488 SingleLine ->
487489 (indent'' /\ indent'' /\ space)
488− typePrefix = case head types of
489− Just type'' -> case SingleLine of
490+ typePrefix = case Array.last types of
491+ Just lastType -> case singleOrMultilineBetween className lastType of
490492 MultipleLines -> newline <> indent
491493 SingleLine -> space
492494 Nothing -> space
@@ -501,7 +503,7 @@ formatInstanceHead indentation indent''
501503 <> formatOneOrDelimited
502504 lines
503505 indent'
504− (formatType indentation indent lines)
506+ (\t -> formatType indentation indent (singleOrMultiline t) t)
505507 constraints
506508 <> formatSourceToken indent' space arrow
507509 )
@@ -717,14 +719,14 @@ formatPatternGuard ::
717719 Indent ->
718720 CST.PatternGuard Void ->
719721 String
720−formatPatternGuard lines indentation indent' patternGuard@(CST.PatternGuard { binder: binder'', expr: expr'}) = do
721− case binder'' of
722+formatPatternGuard lines indentation indent patternGuard@(CST.PatternGuard { binder, expr: expr'}) =
723+ case binder of
722724 Just (binder' /\ arrow) ->
723− formatBinder indentation indent' binder'
724− <> formatSourceToken indent' space arrow
725− <> formatExprPrefix lines indentation indent' expr'
725+ formatBinder indentation indent binder'
726+ <> formatSourceToken indent space arrow
727+ <> formatExprPrefix lines indentation indent expr'
726728 Nothing ->
727− formatExpr indentation indent' expr'
729+ formatExpr indentation indent expr'
728730
729731formatExprPrefix :: Lines -> Indentation -> Indent -> CST.Expr Void -> String
730732formatExprPrefix lines indentation indent' expr =
@@ -1436,20 +1438,52 @@ formatType
14361438 -> CST.Type Void
14371439 -> String
14381440formatType indentation indent lines t = case t of
1441+
1442+ CST.TypeApp typo types ->
1443+ formatType indentation indent (singleOrMultiline typo) typo
1444+ <> formatTypes types -- [TODO] Verify that this works
1445+ where
1446+ { indented, prefix } = case lines of
1447+ MultipleLines -> { indented: indent <> indentation, prefix: newline <> indent <> indentation }
1448+ SingleLine -> { indented: indent, prefix: space }
1449+
1450+ formatTypes = foldMap (\ty -> prefix <> formatType indentation indented (singleOrMultiline ty) ty)
1451+
1452+ CST.TypeArrow t1 arrow t2 ->
1453+ formatType indentation indent (singleOrMultiline t1) t1
1454+ <> space
1455+ <> formatSourceToken indent blank arrow
1456+ <> prefix
1457+ <> formatType indentation indent (singleOrMultiline t2) t2
1458+ where
1459+ prefix = case lines of
1460+ MultipleLines -> newline <> indent
1461+ SingleLine -> space
1462+
1463+ CST.TypeArrowName arrowName ->
1464+ formatSourceToken indent blank arrowName
1465+
14391466 CST.TypeVar name ->
14401467 formatName indent blank name
1468+
14411469 CST.TypeConstructor qualifiedName ->
14421470 formatQualifiedName indent blank qualifiedName
1471+
14431472 CST.TypeWildcard wildcard ->
14441473 formatSourceToken indent blank wildcard
1474+
14451475 CST.TypeHole name ->
14461476 formatName indent blank name
1477+
14471478 CST.TypeString typeString _ ->
14481479 formatSourceToken indent blank typeString
1480+
14491481 CST.TypeRow wrappedRow ->
14501482 formatWrappedRow indentation indent wrappedRow
1483+
14511484 CST.TypeRecord wrappedRow ->
14521485 formatWrappedRow indentation indent wrappedRow
1486+
14531487 CST.TypeForall forAll typeVarBindings dot tailType ->
14541488 formatSourceToken indent blank forAll
14551489 <> formatTypeVarBindings indentation indent (NE.toArray typeVarBindings)
@@ -1460,6 +1494,7 @@ formatType indentation indent lines t = case t of
14601494 prefix = case lines of
14611495 MultipleLines -> newline <> indent
14621496 SingleLine -> space
1497+
14631498 CST.TypeKinded typo colons kind ->
14641499 formatType indentation indent lines typo
14651500 <> space
@@ -1470,15 +1505,7 @@ formatType indentation indent lines t = case t of
14701505 { indented, prefix } = case lines of
14711506 MultipleLines -> { indented: indent <> indentation, prefix: newline <> indent }
14721507 SingleLine -> { indented: indent, prefix: space }
1473− CST.TypeApp typo types ->
1474− formatType indentation indent lines typo
1475− <> formatTypes types -- [TODO] Verify that this works
1476− where
1477− { indented, prefix } = case lines of
1478− MultipleLines -> { indented: indent <> indentation, prefix: newline <> indent }
1479− SingleLine -> { indented: indent, prefix: space }
14801508
1481− formatTypes = foldMap (\typo -> prefix <> formatType indentation indented lines typo)
14821509 CST.TypeOp typo types ->
14831510 formatType indentation indent lines typo
14841511 <> foldMap formatOp types -- [TODO] Verify
@@ -1491,20 +1518,10 @@ formatType indentation indent lines t = case t of
14911518 formatQualifiedName indented prefix op
14921519 <> prefix
14931520 <> formatType indentation indented lines anotherType
1521+
14941522 CST.TypeOpName op ->
14951523 formatQualifiedName indent blank op
1496− CST.TypeArrow t1 arrow t2 ->
1497− formatType indentation indent (singleOrMultiline t1) t1
1498− <> space
1499− <> formatSourceToken indent blank arrow
1500− <> prefix
1501− <> formatType indentation indent (singleOrMultiline t2) t2
1502− where
1503− prefix = case lines of
1504− MultipleLines -> newline <> indent
1505− SingleLine -> space
1506− CST.TypeArrowName arrowName ->
1507− formatSourceToken indent blank arrowName
1524+
15081525 CST.TypeConstrained constraint arrow typo ->
15091526 formatType indentation indent lines constraint
15101527 <> space
@@ -1515,8 +1532,14 @@ formatType indentation indent lines t = case t of
15151532 prefix = case lines of
15161533 MultipleLines -> newline <> indent
15171534 SingleLine -> space
1535+
15181536 CST.TypeParens wrapped ->
1519− formatParens lines indentation indent (\x -> formatType indentation x lines) wrapped
1537+ formatParens lines indentation indent
1538+ (\x wrappedType ->
1539+ formatType indentation x (singleOrMultiline wrappedType) wrappedType
1540+ )
1541+ wrapped
1542+
15201543 CST.TypeUnaryRow sourceToken typo ->
15211544 formatSourceToken indent blank sourceToken
15221545 <> prefix
@@ -1525,6 +1548,7 @@ formatType indentation indent lines t = case t of
15251548 prefix = case lines of
15261549 MultipleLines -> newline <> indent
15271550 SingleLine -> space
1551+
15281552 CST.TypeError e -> absurd e
15291553
15301554formatLabeled
@@ -1574,8 +1598,8 @@ formatParens
15741598 -> (Indent -> a -> String)
15751599 -> CST.Wrapped a
15761600 -> String
1577−formatParens lines indentation indent formatA wrapped = do
1578− formatWrapped indent (formatA indented) wrapped
1601+formatParens lines indentation indent formatValue wrapped = do
1602+ formatWrapped indent (formatValue indented) wrapped
15791603 where
15801604 indented = case lines of
15811605 MultipleLines -> indent <> indentation