@@ -33,7 +33,7 @@ import Data.Tuple (Tuple(..), fst, snd)
33
33
import Dodo as Dodo
34
34
import Partial.Unsafe (unsafeCrashWith )
35
35
import PureScript.CST.Errors (RecoveredError (..))
36
- import PureScript.CST.Types (Binder (..), ClassFundep (..), ClassHead , Comment (..), DataCtor (..), DataHead , DataMembers (..), Declaration (..), Delimited , DelimitedNonEmpty , DoStatement (..), Export (..), Expr (..), FixityOp (..), Foreign (..), Guarded (..), GuardedExpr (..), Ident , IfThenElse , Import (..), ImportDecl (..), Instance (..), InstanceBinding (..), InstanceHead , Label , Labeled (..), LetBinding (..), LineFeed , Module (..), ModuleBody (..), ModuleHeader (..), ModuleName , Name (..), OneOrDelimited (..), Operator , PatternGuard (..), Proper , QualifiedName (..), RecordLabeled (..), RecordUpdate (..), Row (..), Separated (..), SourceStyle (..), SourceToken , Token (..), Type (..), TypeVarBinding (..), ValueBindingFields , Where (..), Wrapped (..))
36
+ import PureScript.CST.Types (AppSpine (..), Binder (..), ClassFundep (..), ClassHead , Comment (..), DataCtor (..), DataHead , DataMembers (..), Declaration (..), Delimited , DelimitedNonEmpty , DoStatement (..), Export (..), Expr (..), FixityOp (..), Foreign (..), Guarded (..), GuardedExpr (..), Ident , IfThenElse , Import (..), ImportDecl (..), Instance (..), InstanceBinding (..), InstanceHead , Label , Labeled (..), LetBinding (..), LineFeed , Module (..), ModuleBody (..), ModuleHeader (..), ModuleName , Name (..), OneOrDelimited (..), Operator , PatternGuard (..), Prefixed (..), Proper , QualifiedName (..), RecordLabeled (..), RecordUpdate (..), Row (..), Separated (..), SourceStyle (..), SourceToken , Token (..), Type (..), TypeVarBinding (..), ValueBindingFields , Where (..), Wrapped (..))
37
37
import Tidy.Doc (FormatDoc , align , alignCurrentColumn , anchor , break , flexDoubleBreak , flexGroup , flexSoftBreak , flexSpaceBreak , forceMinSourceBreaks , fromDoc , indent , joinWith , joinWithMap , leadingBlockComment , leadingLineComment , locally , softBreak , softSpace , sourceBreak , space , spaceBreak , text , trailingBlockComment , trailingLineComment )
38
38
import Tidy.Doc (FormatDoc , toDoc ) as Exports
39
39
import Tidy.Doc as Doc
@@ -193,6 +193,10 @@ formatString = splitStringEscapeLines >>> Array.uncons >>> foldMap \{ head, tail
193
193
formatName :: forall e a n . Format (Name n ) e a
194
194
formatName conf (Name { token }) = formatToken conf token
195
195
196
+ formatPrefixedName :: forall e a n . Format (Prefixed (Name n )) e a
197
+ formatPrefixedName conf (Prefixed { prefix, value: Name { token } }) =
198
+ foldMap (formatToken conf) prefix <> formatToken conf token
199
+
196
200
formatQualifiedName :: forall e a n . Format (QualifiedName n ) e a
197
201
formatQualifiedName conf (QualifiedName { token }) = formatToken conf token
198
202
@@ -514,7 +518,7 @@ formatDataHead :: forall e a. Format (DataHead e) e a
514
518
formatDataHead conf { keyword, name, vars } =
515
519
formatToken conf keyword `space` indent do
516
520
anchor (formatName conf name)
517
- `flexSpaceBreak` joinWithMap spaceBreak (formatTypeVarBinding conf) vars
521
+ `flexSpaceBreak` joinWithMap spaceBreak (formatTypeVarBindingPlain conf) vars
518
522
519
523
formatDataCtor :: forall e a . Format (DataCtor e ) e a
520
524
formatDataCtor conf = Hang .toFormatDoc <<< formatHangingDataCtor conf
@@ -536,7 +540,7 @@ formatClassHead conf (Tuple cls wh) =
536
540
flexGroup do
537
541
formatName conf cls.name
538
542
`spaceBreak`
539
- joinWithMap spaceBreak (indent <<< formatTypeVarBinding conf) cls.vars
543
+ joinWithMap spaceBreak (indent <<< formatTypeVarBindingPlain conf) cls.vars
540
544
`spaceBreak`
541
545
flexGroup do
542
546
anchor (foldMap formatFundeps cls.fundeps)
@@ -618,15 +622,28 @@ formatInstanceBinding conf = case _ of
618
622
InstanceBindingName vbf ->
619
623
formatValueBinding conf vbf
620
624
621
- formatTypeVarBinding :: forall e a . Format (TypeVarBinding e ) e a
625
+ formatTypeVarBinding :: forall e a . Format (TypeVarBinding ( Prefixed ( Name Ident )) e ) e a
622
626
formatTypeVarBinding conf = case _ of
623
627
TypeVarKinded w ->
624
628
formatParensBlock formatKindedTypeVarBinding conf w
625
629
TypeVarName n ->
626
- formatName conf n
630
+ formatPrefixedName conf n
627
631
628
- formatKindedTypeVarBinding :: forall e a . Format (Labeled (Name Ident ) (Type e )) e a
632
+ formatKindedTypeVarBinding :: forall e a . Format (Labeled (Prefixed ( Name Ident ) ) (Type e )) e a
629
633
formatKindedTypeVarBinding conf (Labeled { label, separator, value }) =
634
+ formatPrefixedName conf label `space` indent do
635
+ anchor (formatToken conf separator)
636
+ `flexSpaceBreak` formatType conf value
637
+
638
+ formatTypeVarBindingPlain :: forall e a . Format (TypeVarBinding (Name Ident ) e ) e a
639
+ formatTypeVarBindingPlain conf = case _ of
640
+ TypeVarKinded w ->
641
+ formatParensBlock formatKindedTypeVarBindingPlain conf w
642
+ TypeVarName n ->
643
+ formatName conf n
644
+
645
+ formatKindedTypeVarBindingPlain :: forall e a . Format (Labeled (Name Ident ) (Type e )) e a
646
+ formatKindedTypeVarBindingPlain conf (Labeled { label, separator, value }) =
630
647
formatName conf label `space` indent do
631
648
anchor (formatToken conf separator)
632
649
`flexSpaceBreak` formatType conf value
@@ -720,7 +737,7 @@ formatHangingType :: forall e a. FormatHanging (Type e) e a
720
737
formatHangingType conf = formatHangingPolytype identity conf <<< toPolytype
721
738
722
739
data Poly e
723
- = PolyForall SourceToken (NonEmptyArray (TypeVarBinding e )) SourceToken
740
+ = PolyForall SourceToken (NonEmptyArray (TypeVarBinding ( Prefixed ( Name Ident )) e )) SourceToken
724
741
| PolyArrow (Type e ) SourceToken
725
742
726
743
type Polytype e =
@@ -887,7 +904,7 @@ formatHangingExpr conf = case _ of
887
904
ExprApp expr exprs ->
888
905
hangApp
889
906
(formatHangingExpr conf expr)
890
- (map (formatHangingExpr conf) exprs)
907
+ (map (formatHangingExprAppSpine conf) exprs)
891
908
892
909
ExprLambda lmb ->
893
910
hang
@@ -947,6 +964,13 @@ formatHangingExpr conf = case _ of
947
964
ExprError e ->
948
965
hangBreak $ conf.formatError e
949
966
967
+ formatHangingExprAppSpine :: forall e a . FormatHanging (AppSpine Expr e ) e a
968
+ formatHangingExprAppSpine conf = case _ of
969
+ AppType tok ty ->
970
+ hangBreak $ formatToken conf tok <> formatType conf ty
971
+ AppTerm expr ->
972
+ formatHangingExpr conf expr
973
+
950
974
data ElseIfChain e
951
975
= IfThen SourceToken (Expr e ) SourceToken (Expr e )
952
976
| ElseIfThen SourceToken SourceToken (Expr e ) SourceToken (Expr e )
0 commit comments