@@ -33,7 +33,7 @@ import Data.Tuple (Tuple(..), fst, snd)
3333import Dodo as Dodo
3434import Partial.Unsafe (unsafeCrashWith )
3535import 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 (..))
3737import 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 )
3838import Tidy.Doc (FormatDoc , toDoc ) as Exports
3939import Tidy.Doc as Doc
@@ -193,6 +193,10 @@ formatString = splitStringEscapeLines >>> Array.uncons >>> foldMap \{ head, tail
193193formatName :: forall e a n . Format (Name n ) e a
194194formatName conf (Name { token }) = formatToken conf token
195195
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+
196200formatQualifiedName :: forall e a n . Format (QualifiedName n ) e a
197201formatQualifiedName conf (QualifiedName { token }) = formatToken conf token
198202
@@ -514,7 +518,7 @@ formatDataHead :: forall e a. Format (DataHead e) e a
514518formatDataHead conf { keyword, name, vars } =
515519 formatToken conf keyword `space` indent do
516520 anchor (formatName conf name)
517- `flexSpaceBreak` joinWithMap spaceBreak (formatTypeVarBinding conf) vars
521+ `flexSpaceBreak` joinWithMap spaceBreak (formatTypeVarBindingPlain conf) vars
518522
519523formatDataCtor :: forall e a . Format (DataCtor e ) e a
520524formatDataCtor conf = Hang .toFormatDoc <<< formatHangingDataCtor conf
@@ -536,7 +540,7 @@ formatClassHead conf (Tuple cls wh) =
536540 flexGroup do
537541 formatName conf cls.name
538542 `spaceBreak`
539- joinWithMap spaceBreak (indent <<< formatTypeVarBinding conf) cls.vars
543+ joinWithMap spaceBreak (indent <<< formatTypeVarBindingPlain conf) cls.vars
540544 `spaceBreak`
541545 flexGroup do
542546 anchor (foldMap formatFundeps cls.fundeps)
@@ -618,15 +622,28 @@ formatInstanceBinding conf = case _ of
618622 InstanceBindingName vbf ->
619623 formatValueBinding conf vbf
620624
621- formatTypeVarBinding :: forall e a . Format (TypeVarBinding e ) e a
625+ formatTypeVarBinding :: forall e a . Format (TypeVarBinding ( Prefixed ( Name Ident )) e ) e a
622626formatTypeVarBinding conf = case _ of
623627 TypeVarKinded w ->
624628 formatParensBlock formatKindedTypeVarBinding conf w
625629 TypeVarName n ->
626- formatName conf n
630+ formatPrefixedName conf n
627631
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
629633formatKindedTypeVarBinding 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 }) =
630647 formatName conf label `space` indent do
631648 anchor (formatToken conf separator)
632649 `flexSpaceBreak` formatType conf value
@@ -720,7 +737,7 @@ formatHangingType :: forall e a. FormatHanging (Type e) e a
720737formatHangingType conf = formatHangingPolytype identity conf <<< toPolytype
721738
722739data Poly e
723- = PolyForall SourceToken (NonEmptyArray (TypeVarBinding e )) SourceToken
740+ = PolyForall SourceToken (NonEmptyArray (TypeVarBinding ( Prefixed ( Name Ident )) e )) SourceToken
724741 | PolyArrow (Type e ) SourceToken
725742
726743type Polytype e =
@@ -887,7 +904,7 @@ formatHangingExpr conf = case _ of
887904 ExprApp expr exprs ->
888905 hangApp
889906 (formatHangingExpr conf expr)
890- (map (formatHangingExpr conf) exprs)
907+ (map (formatHangingExprAppSpine conf) exprs)
891908
892909 ExprLambda lmb ->
893910 hang
@@ -947,6 +964,13 @@ formatHangingExpr conf = case _ of
947964 ExprError e ->
948965 hangBreak $ conf.formatError e
949966
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+
950974data ElseIfChain e
951975 = IfThen SourceToken (Expr e ) SourceToken (Expr e )
952976 | ElseIfThen SourceToken SourceToken (Expr e ) SourceToken (Expr e )
0 commit comments