module Language.PureScript.CST.Flatten where

import Prelude

import Data.DList (DList)
import Language.PureScript.CST.Types
import Language.PureScript.CST.Positions (advanceLeading, moduleRange, srcRange)

flattenModule :: Module a -> DList SourceToken
flattenModule :: forall a. Module a -> DList SourceToken
flattenModule m :: Module a
m@(Module a
_ SourceToken
a Name ModuleName
b Maybe (DelimitedNonEmpty (Export a))
c SourceToken
d [ImportDecl a]
e [Declaration a]
f [Comment LineFeed]
g) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<>
  forall a. Name a -> DList SourceToken
flattenName Name ModuleName
b forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. Export a -> DList SourceToken
flattenExport)) Maybe (DelimitedNonEmpty (Export a))
c forall a. Semigroup a => a -> a -> a
<>
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
d forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. ImportDecl a -> DList SourceToken
flattenImportDecl [ImportDecl a]
e forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Declaration a -> DList SourceToken
flattenDeclaration [Declaration a]
f forall a. Semigroup a => a -> a -> a
<>
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (TokenAnn -> Token -> SourceToken
SourceToken (SourceRange -> [Comment LineFeed] -> [Comment Void] -> TokenAnn
TokenAnn SourceRange
eofRange [Comment LineFeed]
g []) Token
TokEof)
  where
    (SourceToken
_, SourceToken
endTkn) = forall a. Module a -> (SourceToken, SourceToken)
moduleRange Module a
m
    eofPos :: SourcePos
eofPos = SourcePos -> [Comment LineFeed] -> SourcePos
advanceLeading (SourceRange -> SourcePos
srcEnd (SourceToken -> SourceRange
srcRange SourceToken
endTkn)) [Comment LineFeed]
g
    eofRange :: SourceRange
eofRange = SourcePos -> SourcePos -> SourceRange
SourceRange SourcePos
eofPos SourcePos
eofPos

flattenDataHead :: DataHead a -> DList SourceToken
flattenDataHead :: forall a. DataHead a -> DList SourceToken
flattenDataHead (DataHead SourceToken
a Name (ProperName 'TypeName)
b [TypeVarBinding a]
c) = forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'TypeName)
b forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. TypeVarBinding a -> DList SourceToken
flattenTypeVarBinding [TypeVarBinding a]
c

flattenDataCtor :: DataCtor a -> DList SourceToken
flattenDataCtor :: forall a. DataCtor a -> DList SourceToken
flattenDataCtor (DataCtor a
_ Name (ProperName 'ConstructorName)
a [Type a]
b) = forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'ConstructorName)
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Type a -> DList SourceToken
flattenType [Type a]
b

flattenClassHead :: ClassHead a -> DList SourceToken
flattenClassHead :: forall a. ClassHead a -> DList SourceToken
flattenClassHead (ClassHead SourceToken
a Maybe (OneOrDelimited (Constraint a), SourceToken)
b Name (ProperName 'ClassName)
c [TypeVarBinding a]
d Maybe (SourceToken, Separated ClassFundep)
e) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(OneOrDelimited (Constraint a)
f, SourceToken
g) -> forall a.
(a -> DList SourceToken) -> OneOrDelimited a -> DList SourceToken
flattenOneOrDelimited forall a. Constraint a -> DList SourceToken
flattenConstraint OneOrDelimited (Constraint a)
f forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
g) Maybe (OneOrDelimited (Constraint a), SourceToken)
b forall a. Semigroup a => a -> a -> a
<>
  forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'ClassName)
c forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. TypeVarBinding a -> DList SourceToken
flattenTypeVarBinding [TypeVarBinding a]
d forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SourceToken
f, Separated ClassFundep
g) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
f forall a. Semigroup a => a -> a -> a
<> forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated ClassFundep -> DList SourceToken
flattenClassFundep Separated ClassFundep
g) Maybe (SourceToken, Separated ClassFundep)
e

flattenClassFundep :: ClassFundep -> DList SourceToken
flattenClassFundep :: ClassFundep -> DList SourceToken
flattenClassFundep = \case
  FundepDetermined SourceToken
a NonEmpty (Name Ident)
b ->
    forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Name a -> DList SourceToken
flattenName NonEmpty (Name Ident)
b
  FundepDetermines NonEmpty (Name Ident)
a SourceToken
b NonEmpty (Name Ident)
c ->
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Name a -> DList SourceToken
flattenName NonEmpty (Name Ident)
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Name a -> DList SourceToken
flattenName NonEmpty (Name Ident)
c

flattenInstance :: Instance a -> DList SourceToken
flattenInstance :: forall a. Instance a -> DList SourceToken
flattenInstance (Instance InstanceHead a
a Maybe (SourceToken, NonEmpty (InstanceBinding a))
b) =
  forall a. InstanceHead a -> DList SourceToken
flattenInstanceHead InstanceHead a
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SourceToken
c, NonEmpty (InstanceBinding a)
d) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. InstanceBinding a -> DList SourceToken
flattenInstanceBinding NonEmpty (InstanceBinding a)
d) Maybe (SourceToken, NonEmpty (InstanceBinding a))
b

flattenInstanceHead :: InstanceHead a -> DList SourceToken
flattenInstanceHead :: forall a. InstanceHead a -> DList SourceToken
flattenInstanceHead (InstanceHead SourceToken
a Maybe (Name Ident, SourceToken)
b Maybe (OneOrDelimited (Constraint a), SourceToken)
c QualifiedName (ProperName 'ClassName)
d [Type a]
e) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(Name Ident
n, SourceToken
s) -> forall a. Name a -> DList SourceToken
flattenName Name Ident
n forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
s) Maybe (Name Ident, SourceToken)
b forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(OneOrDelimited (Constraint a)
g, SourceToken
h) -> forall a.
(a -> DList SourceToken) -> OneOrDelimited a -> DList SourceToken
flattenOneOrDelimited forall a. Constraint a -> DList SourceToken
flattenConstraint OneOrDelimited (Constraint a)
g forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
h) Maybe (OneOrDelimited (Constraint a), SourceToken)
c forall a. Semigroup a => a -> a -> a
<>
  forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName (ProperName 'ClassName)
d forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Type a -> DList SourceToken
flattenType [Type a]
e

flattenInstanceBinding :: InstanceBinding a -> DList SourceToken
flattenInstanceBinding :: forall a. InstanceBinding a -> DList SourceToken
flattenInstanceBinding = \case
  InstanceBindingSignature a
_ Labeled (Name Ident) (Type a)
a -> forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled forall a. Name a -> DList SourceToken
flattenName forall a. Type a -> DList SourceToken
flattenType Labeled (Name Ident) (Type a)
a
  InstanceBindingName a
_ ValueBindingFields a
a -> forall a. ValueBindingFields a -> DList SourceToken
flattenValueBindingFields ValueBindingFields a
a

flattenValueBindingFields :: ValueBindingFields a -> DList SourceToken
flattenValueBindingFields :: forall a. ValueBindingFields a -> DList SourceToken
flattenValueBindingFields (ValueBindingFields Name Ident
a [Binder a]
b Guarded a
c) =
  forall a. Name a -> DList SourceToken
flattenName Name Ident
a forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Binder a -> DList SourceToken
flattenBinder [Binder a]
b forall a. Semigroup a => a -> a -> a
<>
  forall a. Guarded a -> DList SourceToken
flattenGuarded Guarded a
c

flattenBinder :: Binder a -> DList SourceToken
flattenBinder :: forall a. Binder a -> DList SourceToken
flattenBinder = \case
  BinderWildcard a
_ SourceToken
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  BinderVar a
_ Name Ident
a -> forall a. Name a -> DList SourceToken
flattenName Name Ident
a
  BinderNamed a
_ Name Ident
a SourceToken
b Binder a
c -> forall a. Name a -> DList SourceToken
flattenName Name Ident
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Binder a -> DList SourceToken
flattenBinder Binder a
c
  BinderConstructor a
_ QualifiedName (ProperName 'ConstructorName)
a [Binder a]
b -> forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName (ProperName 'ConstructorName)
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Binder a -> DList SourceToken
flattenBinder [Binder a]
b
  BinderBoolean a
_ SourceToken
a Bool
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  BinderChar a
_ SourceToken
a Char
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  BinderString a
_ SourceToken
a PSString
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  BinderNumber a
_ Maybe SourceToken
a SourceToken
b Either Integer Double
_ -> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b
  BinderArray a
_ Delimited (Binder a)
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. Binder a -> DList SourceToken
flattenBinder)) Delimited (Binder a)
a
  BinderRecord a
_ Delimited (RecordLabeled (Binder a))
a ->
    forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated (forall a.
(a -> DList SourceToken) -> RecordLabeled a -> DList SourceToken
flattenRecordLabeled forall a. Binder a -> DList SourceToken
flattenBinder))) Delimited (RecordLabeled (Binder a))
a
  BinderParens a
_ Wrapped (Binder a)
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped forall a. Binder a -> DList SourceToken
flattenBinder Wrapped (Binder a)
a
  BinderTyped a
_ Binder a
a SourceToken
b Type a
c -> forall a. Binder a -> DList SourceToken
flattenBinder Binder a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
c
  BinderOp a
_ Binder a
a QualifiedName (OpName 'ValueOpName)
b Binder a
c -> forall a. Binder a -> DList SourceToken
flattenBinder Binder a
a forall a. Semigroup a => a -> a -> a
<> forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName (OpName 'ValueOpName)
b forall a. Semigroup a => a -> a -> a
<> forall a. Binder a -> DList SourceToken
flattenBinder Binder a
c

flattenRecordLabeled :: (a -> DList SourceToken) -> RecordLabeled a -> DList SourceToken
flattenRecordLabeled :: forall a.
(a -> DList SourceToken) -> RecordLabeled a -> DList SourceToken
flattenRecordLabeled a -> DList SourceToken
f = \case
  RecordPun Name Ident
a -> forall a. Name a -> DList SourceToken
flattenName Name Ident
a
  RecordField Label
a SourceToken
b a
c -> Label -> DList SourceToken
flattenLabel Label
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> a -> DList SourceToken
f a
c

flattenRecordAccessor :: RecordAccessor a -> DList SourceToken
flattenRecordAccessor :: forall a. RecordAccessor a -> DList SourceToken
flattenRecordAccessor (RecordAccessor Expr a
a SourceToken
b Separated Label
c) =
  forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated Label -> DList SourceToken
flattenLabel Separated Label
c

flattenRecordUpdate :: RecordUpdate a -> DList SourceToken
flattenRecordUpdate :: forall a. RecordUpdate a -> DList SourceToken
flattenRecordUpdate = \case
  RecordUpdateLeaf Label
a SourceToken
b Expr a
c -> Label -> DList SourceToken
flattenLabel Label
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
c
  RecordUpdateBranch Label
a DelimitedNonEmpty (RecordUpdate a)
b ->
    Label -> DList SourceToken
flattenLabel Label
a forall a. Semigroup a => a -> a -> a
<> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. RecordUpdate a -> DList SourceToken
flattenRecordUpdate) DelimitedNonEmpty (RecordUpdate a)
b

flattenLambda :: Lambda a -> DList SourceToken
flattenLambda :: forall a. Lambda a -> DList SourceToken
flattenLambda (Lambda SourceToken
a NonEmpty (Binder a)
b SourceToken
c Expr a
d) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Binder a -> DList SourceToken
flattenBinder NonEmpty (Binder a)
b forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
d

flattenIfThenElse :: IfThenElse a -> DList SourceToken
flattenIfThenElse :: forall a. IfThenElse a -> DList SourceToken
flattenIfThenElse (IfThenElse SourceToken
a Expr a
b SourceToken
c Expr a
d SourceToken
e Expr a
f) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
b forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
d forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
e forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
f

flattenCaseOf :: CaseOf a -> DList SourceToken
flattenCaseOf :: forall a. CaseOf a -> DList SourceToken
flattenCaseOf (CaseOf SourceToken
a Separated (Expr a)
b SourceToken
c NonEmpty (Separated (Binder a), Guarded a)
d) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<>
  forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. Expr a -> DList SourceToken
flattenExpr Separated (Expr a)
b forall a. Semigroup a => a -> a -> a
<>
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(Separated (Binder a)
e, Guarded a
f) -> forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. Binder a -> DList SourceToken
flattenBinder Separated (Binder a)
e forall a. Semigroup a => a -> a -> a
<> forall a. Guarded a -> DList SourceToken
flattenGuarded Guarded a
f) NonEmpty (Separated (Binder a), Guarded a)
d

flattenLetIn :: LetIn a -> DList SourceToken
flattenLetIn :: forall a. LetIn a -> DList SourceToken
flattenLetIn (LetIn SourceToken
a NonEmpty (LetBinding a)
b SourceToken
c Expr a
d) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. LetBinding a -> DList SourceToken
flattenLetBinding NonEmpty (LetBinding a)
b forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
d

flattenDoBlock :: DoBlock a -> DList SourceToken
flattenDoBlock :: forall a. DoBlock a -> DList SourceToken
flattenDoBlock (DoBlock SourceToken
a NonEmpty (DoStatement a)
b) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. DoStatement a -> DList SourceToken
flattenDoStatement NonEmpty (DoStatement a)
b

flattenAdoBlock :: AdoBlock a -> DList SourceToken
flattenAdoBlock :: forall a. AdoBlock a -> DList SourceToken
flattenAdoBlock (AdoBlock SourceToken
a [DoStatement a]
b SourceToken
c Expr a
d) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. DoStatement a -> DList SourceToken
flattenDoStatement [DoStatement a]
b forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
d

flattenDoStatement :: DoStatement a -> DList SourceToken
flattenDoStatement :: forall a. DoStatement a -> DList SourceToken
flattenDoStatement = \case
  DoLet SourceToken
a NonEmpty (LetBinding a)
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. LetBinding a -> DList SourceToken
flattenLetBinding NonEmpty (LetBinding a)
b
  DoDiscard Expr a
a -> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a
  DoBind Binder a
a SourceToken
b Expr a
c -> forall a. Binder a -> DList SourceToken
flattenBinder Binder a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
c

flattenExpr :: Expr a -> DList SourceToken
flattenExpr :: forall a. Expr a -> DList SourceToken
flattenExpr = \case
  ExprHole a
_ Name Ident
a -> forall a. Name a -> DList SourceToken
flattenName Name Ident
a
  ExprSection a
_ SourceToken
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  ExprIdent a
_ QualifiedName Ident
a -> forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName Ident
a
  ExprConstructor a
_ QualifiedName (ProperName 'ConstructorName)
a -> forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName (ProperName 'ConstructorName)
a
  ExprBoolean a
_ SourceToken
a Bool
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  ExprChar a
_ SourceToken
a Char
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  ExprString a
_ SourceToken
a PSString
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  ExprNumber a
_ SourceToken
a Either Integer Double
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  ExprArray a
_ Delimited (Expr a)
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. Expr a -> DList SourceToken
flattenExpr)) Delimited (Expr a)
a
  ExprRecord a
_ Delimited (RecordLabeled (Expr a))
a ->
    forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated (forall a.
(a -> DList SourceToken) -> RecordLabeled a -> DList SourceToken
flattenRecordLabeled forall a. Expr a -> DList SourceToken
flattenExpr))) Delimited (RecordLabeled (Expr a))
a
  ExprParens a
_ Wrapped (Expr a)
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped forall a. Expr a -> DList SourceToken
flattenExpr Wrapped (Expr a)
a
  ExprTyped a
_ Expr a
a SourceToken
b Type a
c -> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
c
  ExprInfix a
_ Expr a
a Wrapped (Expr a)
b Expr a
c -> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a forall a. Semigroup a => a -> a -> a
<> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped forall a. Expr a -> DList SourceToken
flattenExpr Wrapped (Expr a)
b forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
c
  ExprOp a
_ Expr a
a QualifiedName (OpName 'ValueOpName)
b Expr a
c -> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a forall a. Semigroup a => a -> a -> a
<> forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName (OpName 'ValueOpName)
b forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
c
  ExprOpName a
_ QualifiedName (OpName 'ValueOpName)
a -> forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName (OpName 'ValueOpName)
a
  ExprNegate a
_ SourceToken
a Expr a
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
b
  ExprRecordAccessor a
_ RecordAccessor a
a -> forall a. RecordAccessor a -> DList SourceToken
flattenRecordAccessor RecordAccessor a
a
  ExprRecordUpdate a
_ Expr a
a DelimitedNonEmpty (RecordUpdate a)
b -> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a forall a. Semigroup a => a -> a -> a
<> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. RecordUpdate a -> DList SourceToken
flattenRecordUpdate) DelimitedNonEmpty (RecordUpdate a)
b
  ExprApp a
_ Expr a
a Expr a
b -> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
b
  ExprVisibleTypeApp  a
_ Expr a
a SourceToken
b Type a
c -> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
c
  ExprLambda a
_ Lambda a
a -> forall a. Lambda a -> DList SourceToken
flattenLambda Lambda a
a
  ExprIf a
_ IfThenElse a
a -> forall a. IfThenElse a -> DList SourceToken
flattenIfThenElse IfThenElse a
a
  ExprCase a
_ CaseOf a
a -> forall a. CaseOf a -> DList SourceToken
flattenCaseOf CaseOf a
a
  ExprLet a
_ LetIn a
a -> forall a. LetIn a -> DList SourceToken
flattenLetIn LetIn a
a
  ExprDo a
_ DoBlock a
a -> forall a. DoBlock a -> DList SourceToken
flattenDoBlock DoBlock a
a
  ExprAdo a
_ AdoBlock a
a -> forall a. AdoBlock a -> DList SourceToken
flattenAdoBlock AdoBlock a
a

flattenLetBinding :: LetBinding a -> DList SourceToken
flattenLetBinding :: forall a. LetBinding a -> DList SourceToken
flattenLetBinding = \case
  LetBindingSignature a
_ Labeled (Name Ident) (Type a)
a -> forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled forall a. Name a -> DList SourceToken
flattenName forall a. Type a -> DList SourceToken
flattenType Labeled (Name Ident) (Type a)
a
  LetBindingName a
_ ValueBindingFields a
a -> forall a. ValueBindingFields a -> DList SourceToken
flattenValueBindingFields ValueBindingFields a
a
  LetBindingPattern a
_ Binder a
a SourceToken
b Where a
c -> forall a. Binder a -> DList SourceToken
flattenBinder Binder a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Where a -> DList SourceToken
flattenWhere Where a
c

flattenWhere :: Where a -> DList SourceToken
flattenWhere :: forall a. Where a -> DList SourceToken
flattenWhere (Where Expr a
a Maybe (SourceToken, NonEmpty (LetBinding a))
b) =
  forall a. Expr a -> DList SourceToken
flattenExpr Expr a
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SourceToken
c, NonEmpty (LetBinding a)
d) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. LetBinding a -> DList SourceToken
flattenLetBinding NonEmpty (LetBinding a)
d) Maybe (SourceToken, NonEmpty (LetBinding a))
b

flattenPatternGuard :: PatternGuard a -> DList SourceToken
flattenPatternGuard :: forall a. PatternGuard a -> DList SourceToken
flattenPatternGuard (PatternGuard Maybe (Binder a, SourceToken)
a Expr a
b) =
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(Binder a
c, SourceToken
d) -> forall a. Binder a -> DList SourceToken
flattenBinder Binder a
c forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
d) Maybe (Binder a, SourceToken)
a forall a. Semigroup a => a -> a -> a
<> forall a. Expr a -> DList SourceToken
flattenExpr Expr a
b

flattenGuardedExpr :: GuardedExpr a -> DList SourceToken
flattenGuardedExpr :: forall a. GuardedExpr a -> DList SourceToken
flattenGuardedExpr (GuardedExpr SourceToken
a Separated (PatternGuard a)
b SourceToken
c Where a
d) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<>
  forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. PatternGuard a -> DList SourceToken
flattenPatternGuard Separated (PatternGuard a)
b forall a. Semigroup a => a -> a -> a
<>
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<>
  forall a. Where a -> DList SourceToken
flattenWhere Where a
d

flattenGuarded :: Guarded a -> DList SourceToken
flattenGuarded :: forall a. Guarded a -> DList SourceToken
flattenGuarded = \case
  Unconditional SourceToken
a Where a
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a. Where a -> DList SourceToken
flattenWhere Where a
b
  Guarded NonEmpty (GuardedExpr a)
a -> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. GuardedExpr a -> DList SourceToken
flattenGuardedExpr NonEmpty (GuardedExpr a)
a

flattenFixityFields :: FixityFields -> DList SourceToken
flattenFixityFields :: FixityFields -> DList SourceToken
flattenFixityFields (FixityFields (SourceToken
a, Fixity
_) (SourceToken
b, Integer
_) FixityOp
c) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> FixityOp -> DList SourceToken
flattenFixityOp FixityOp
c

flattenFixityOp :: FixityOp -> DList SourceToken
flattenFixityOp :: FixityOp -> DList SourceToken
flattenFixityOp = \case
  FixityValue QualifiedName (Either Ident (ProperName 'ConstructorName))
a SourceToken
b Name (OpName 'ValueOpName)
c -> forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName (Either Ident (ProperName 'ConstructorName))
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (OpName 'ValueOpName)
c
  FixityType SourceToken
a QualifiedName (ProperName 'TypeName)
b SourceToken
c Name (OpName 'TypeOpName)
d -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName QualifiedName (ProperName 'TypeName)
b forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (OpName 'TypeOpName)
d

flattenForeign :: Foreign a -> DList SourceToken
flattenForeign :: forall a. Foreign a -> DList SourceToken
flattenForeign = \case
  ForeignValue Labeled (Name Ident) (Type a)
a -> forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled forall a. Name a -> DList SourceToken
flattenName forall a. Type a -> DList SourceToken
flattenType Labeled (Name Ident) (Type a)
a
  ForeignData SourceToken
a Labeled (Name (ProperName 'TypeName)) (Type a)
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled forall a. Name a -> DList SourceToken
flattenName forall a. Type a -> DList SourceToken
flattenType Labeled (Name (ProperName 'TypeName)) (Type a)
b
  ForeignKind SourceToken
a Name (ProperName 'TypeName)
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'TypeName)
b

flattenRole :: Role -> DList SourceToken
flattenRole :: Role -> DList SourceToken
flattenRole = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Role -> SourceToken
roleTok

flattenDeclaration :: Declaration a -> DList SourceToken
flattenDeclaration :: forall a. Declaration a -> DList SourceToken
flattenDeclaration = \case
  DeclData a
_ DataHead a
a Maybe (SourceToken, Separated (DataCtor a))
b ->
    forall a. DataHead a -> DList SourceToken
flattenDataHead DataHead a
a forall a. Semigroup a => a -> a -> a
<>
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SourceToken
t, Separated (DataCtor a)
cs) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
t forall a. Semigroup a => a -> a -> a
<> forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. DataCtor a -> DList SourceToken
flattenDataCtor Separated (DataCtor a)
cs) Maybe (SourceToken, Separated (DataCtor a))
b
  DeclType a
_ DataHead a
a SourceToken
b Type a
c ->forall a. DataHead a -> DList SourceToken
flattenDataHead DataHead a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
c
  DeclNewtype a
_ DataHead a
a SourceToken
b Name (ProperName 'ConstructorName)
c Type a
d -> forall a. DataHead a -> DList SourceToken
flattenDataHead DataHead a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'ConstructorName)
c forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
d
  DeclClass a
_ ClassHead a
a Maybe (SourceToken, NonEmpty (Labeled (Name Ident) (Type a)))
b ->
    forall a. ClassHead a -> DList SourceToken
flattenClassHead ClassHead a
a forall a. Semigroup a => a -> a -> a
<>
    forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SourceToken
c, NonEmpty (Labeled (Name Ident) (Type a))
d) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled forall a. Name a -> DList SourceToken
flattenName forall a. Type a -> DList SourceToken
flattenType) NonEmpty (Labeled (Name Ident) (Type a))
d) Maybe (SourceToken, NonEmpty (Labeled (Name Ident) (Type a)))
b
  DeclInstanceChain a
_ Separated (Instance a)
a -> forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. Instance a -> DList SourceToken
flattenInstance Separated (Instance a)
a
  DeclDerive a
_ SourceToken
a Maybe SourceToken
b InstanceHead a
c -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. InstanceHead a -> DList SourceToken
flattenInstanceHead InstanceHead a
c
  DeclKindSignature a
_ SourceToken
a Labeled (Name (ProperName 'TypeName)) (Type a)
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled forall a. Name a -> DList SourceToken
flattenName forall a. Type a -> DList SourceToken
flattenType Labeled (Name (ProperName 'TypeName)) (Type a)
b
  DeclSignature a
_ Labeled (Name Ident) (Type a)
a -> forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled forall a. Name a -> DList SourceToken
flattenName forall a. Type a -> DList SourceToken
flattenType Labeled (Name Ident) (Type a)
a
  DeclFixity a
_ FixityFields
a -> FixityFields -> DList SourceToken
flattenFixityFields FixityFields
a
  DeclForeign a
_ SourceToken
a SourceToken
b Foreign a
c -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Foreign a -> DList SourceToken
flattenForeign Foreign a
c
  DeclRole a
_ SourceToken
a SourceToken
b Name (ProperName 'TypeName)
c NonEmpty Role
d -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'TypeName)
c forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Role -> DList SourceToken
flattenRole NonEmpty Role
d
  DeclValue a
_ ValueBindingFields a
a -> forall a. ValueBindingFields a -> DList SourceToken
flattenValueBindingFields ValueBindingFields a
a

flattenQualifiedName :: QualifiedName a -> DList SourceToken
flattenQualifiedName :: forall a. QualifiedName a -> DList SourceToken
flattenQualifiedName = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. QualifiedName a -> SourceToken
qualTok

flattenName :: Name a -> DList SourceToken
flattenName :: forall a. Name a -> DList SourceToken
flattenName = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Name a -> SourceToken
nameTok

flattenLabel :: Label -> DList SourceToken
flattenLabel :: Label -> DList SourceToken
flattenLabel = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Label -> SourceToken
lblTok

flattenExport :: Export a -> DList SourceToken
flattenExport :: forall a. Export a -> DList SourceToken
flattenExport = \case
  ExportValue a
_ Name Ident
n -> forall a. Name a -> DList SourceToken
flattenName Name Ident
n
  ExportOp a
_ Name (OpName 'ValueOpName)
n -> forall a. Name a -> DList SourceToken
flattenName Name (OpName 'ValueOpName)
n
  ExportType a
_ Name (ProperName 'TypeName)
n Maybe (DataMembers a)
dms -> forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'TypeName)
n forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. DataMembers a -> DList SourceToken
flattenDataMembers Maybe (DataMembers a)
dms
  ExportTypeOp a
_ SourceToken
t Name (OpName 'TypeOpName)
n -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
t forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (OpName 'TypeOpName)
n
  ExportClass a
_ SourceToken
t Name (ProperName 'ClassName)
n -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
t forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'ClassName)
n
  ExportModule a
_ SourceToken
t Name ModuleName
n -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
t forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name ModuleName
n

flattenDataMembers :: DataMembers a -> DList SourceToken
flattenDataMembers :: forall a. DataMembers a -> DList SourceToken
flattenDataMembers = \case
  DataAll a
_ SourceToken
t -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
t
  DataEnumerated a
_ Delimited (Name (ProperName 'ConstructorName))
ns -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. Name a -> DList SourceToken
flattenName)) Delimited (Name (ProperName 'ConstructorName))
ns

flattenImportDecl :: ImportDecl a -> DList SourceToken
flattenImportDecl :: forall a. ImportDecl a -> DList SourceToken
flattenImportDecl (ImportDecl a
_ SourceToken
a Name ModuleName
b Maybe (Maybe SourceToken, DelimitedNonEmpty (Import a))
c Maybe (SourceToken, Name ModuleName)
d) =
  forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<>
  forall a. Name a -> DList SourceToken
flattenName Name ModuleName
b forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(Maybe SourceToken
mt, DelimitedNonEmpty (Import a)
is) ->
             forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe SourceToken
mt forall a. Semigroup a => a -> a -> a
<> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated forall a. Import a -> DList SourceToken
flattenImport) DelimitedNonEmpty (Import a)
is) Maybe (Maybe SourceToken, DelimitedNonEmpty (Import a))
c forall a. Semigroup a => a -> a -> a
<>
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SourceToken
t, Name ModuleName
n) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
t forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name ModuleName
n) Maybe (SourceToken, Name ModuleName)
d

flattenImport :: Import a -> DList SourceToken
flattenImport :: forall a. Import a -> DList SourceToken
flattenImport = \case
  ImportValue a
_ Name Ident
n -> forall a. Name a -> DList SourceToken
flattenName Name Ident
n
  ImportOp a
_ Name (OpName 'ValueOpName)
n -> forall a. Name a -> DList SourceToken
flattenName Name (OpName 'ValueOpName)
n
  ImportType a
_ Name (ProperName 'TypeName)
n Maybe (DataMembers a)
dms -> forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'TypeName)
n forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. DataMembers a -> DList SourceToken
flattenDataMembers Maybe (DataMembers a)
dms
  ImportTypeOp a
_ SourceToken
t Name (OpName 'TypeOpName)
n -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
t forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (OpName 'TypeOpName)
n
  ImportClass a
_ SourceToken
t Name (ProperName 'ClassName)
n -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
t forall a. Semigroup a => a -> a -> a
<> forall a. Name a -> DList SourceToken
flattenName Name (ProperName 'ClassName)
n

flattenWrapped :: (a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped :: forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped a -> DList SourceToken
k (Wrapped SourceToken
a a
b SourceToken
c) = forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> a -> DList SourceToken
k a
b forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c

flattenSeparated :: (a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated :: forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated a -> DList SourceToken
k (Separated a
a [(SourceToken, a)]
b) = a -> DList SourceToken
k a
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SourceToken
c, a
d) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> a -> DList SourceToken
k a
d) [(SourceToken, a)]
b

flattenOneOrDelimited
  :: (a -> DList SourceToken) -> OneOrDelimited a -> DList SourceToken
flattenOneOrDelimited :: forall a.
(a -> DList SourceToken) -> OneOrDelimited a -> DList SourceToken
flattenOneOrDelimited a -> DList SourceToken
f = \case
  One a
a -> a -> DList SourceToken
f a
a
  Many DelimitedNonEmpty a
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated a -> DList SourceToken
f) DelimitedNonEmpty a
a

flattenLabeled :: (a -> DList SourceToken) -> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled :: forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled a -> DList SourceToken
ka b -> DList SourceToken
kc (Labeled a
a SourceToken
b b
c) = a -> DList SourceToken
ka a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> b -> DList SourceToken
kc b
c

flattenType :: Type a -> DList SourceToken
flattenType :: forall a. Type a -> DList SourceToken
flattenType = \case
  TypeVar a
_ Name Ident
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Name a -> SourceToken
nameTok Name Ident
a
  TypeConstructor a
_ QualifiedName (ProperName 'TypeName)
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. QualifiedName a -> SourceToken
qualTok QualifiedName (ProperName 'TypeName)
a
  TypeWildcard a
_ SourceToken
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  TypeHole a
_ Name Ident
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Name a -> SourceToken
nameTok Name Ident
a
  TypeString a
_ SourceToken
a PSString
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  TypeInt a
_ Maybe SourceToken
a SourceToken
b Integer
_ -> forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b
  TypeRow a
_ Wrapped (Row a)
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped forall a. Row a -> DList SourceToken
flattenRow Wrapped (Row a)
a
  TypeRecord a
_ Wrapped (Row a)
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped forall a. Row a -> DList SourceToken
flattenRow Wrapped (Row a)
a
  TypeForall a
_ SourceToken
a NonEmpty (TypeVarBinding a)
b SourceToken
c Type a
d -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. TypeVarBinding a -> DList SourceToken
flattenTypeVarBinding NonEmpty (TypeVarBinding a)
b forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
c forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
d
  TypeKinded a
_ Type a
a SourceToken
b Type a
c -> forall a. Type a -> DList SourceToken
flattenType Type a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
c
  TypeApp a
_ Type a
a Type a
b -> forall a. Type a -> DList SourceToken
flattenType Type a
a forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
b
  TypeOp a
_ Type a
a QualifiedName (OpName 'TypeOpName)
b Type a
c -> forall a. Type a -> DList SourceToken
flattenType Type a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. QualifiedName a -> SourceToken
qualTok QualifiedName (OpName 'TypeOpName)
b) forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
c
  TypeOpName a
_ QualifiedName (OpName 'TypeOpName)
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. QualifiedName a -> SourceToken
qualTok QualifiedName (OpName 'TypeOpName)
a
  TypeArr a
_ Type a
a SourceToken
b Type a
c -> forall a. Type a -> DList SourceToken
flattenType Type a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
c
  TypeArrName a
_ SourceToken
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a
  TypeConstrained a
_ Constraint a
a SourceToken
b Type a
c -> forall a. Constraint a -> DList SourceToken
flattenConstraint Constraint a
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
b forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
c
  TypeParens a
_ Wrapped (Type a)
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped forall a. Type a -> DList SourceToken
flattenType Wrapped (Type a)
a
  TypeUnaryRow a
_ SourceToken
a Type a
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
b

flattenRow :: Row a -> DList SourceToken
flattenRow :: forall a. Row a -> DList SourceToken
flattenRow (Row Maybe (Separated (Labeled Label (Type a)))
lbls Maybe (SourceToken, Type a)
tl) =
  forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (forall a.
(a -> DList SourceToken) -> Separated a -> DList SourceToken
flattenSeparated (forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Label -> SourceToken
lblTok) forall a. Type a -> DList SourceToken
flattenType)) Maybe (Separated (Labeled Label (Type a)))
lbls
    forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(SourceToken
a, Type a
b) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall a. Type a -> DList SourceToken
flattenType Type a
b) Maybe (SourceToken, Type a)
tl

flattenTypeVarBinding :: TypeVarBinding a -> DList SourceToken
flattenTypeVarBinding :: forall a. TypeVarBinding a -> DList SourceToken
flattenTypeVarBinding = \case
  TypeVarKinded Wrapped (Labeled (Maybe SourceToken, Name Ident) (Type a))
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped (forall a b.
(a -> DList SourceToken)
-> (b -> DList SourceToken) -> Labeled a b -> DList SourceToken
flattenLabeled forall {f :: * -> *} {a}.
(Monoid (f SourceToken), Applicative f) =>
(Maybe SourceToken, Name a) -> f SourceToken
go forall a. Type a -> DList SourceToken
flattenType) Wrapped (Labeled (Maybe SourceToken, Name Ident) (Type a))
a
  TypeVarName (Maybe SourceToken, Name Ident)
a -> forall {f :: * -> *} {a}.
(Monoid (f SourceToken), Applicative f) =>
(Maybe SourceToken, Name a) -> f SourceToken
go (Maybe SourceToken, Name Ident)
a
  where
  go :: (Maybe SourceToken, Name a) -> f SourceToken
go (Maybe SourceToken
a, Name a
b) = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe SourceToken
a forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. Name a -> SourceToken
nameTok Name a
b)

flattenConstraint :: Constraint a -> DList SourceToken
flattenConstraint :: forall a. Constraint a -> DList SourceToken
flattenConstraint = \case
  Constraint a
_ QualifiedName (ProperName 'ClassName)
a [Type a]
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. QualifiedName a -> SourceToken
qualTok QualifiedName (ProperName 'ClassName)
a) forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall a. Type a -> DList SourceToken
flattenType [Type a]
b
  ConstraintParens a
_ Wrapped (Constraint a)
a -> forall a.
(a -> DList SourceToken) -> Wrapped a -> DList SourceToken
flattenWrapped forall a. Constraint a -> DList SourceToken
flattenConstraint Wrapped (Constraint a)
a