@@ -11,7 +11,7 @@ module Purepur.PurescriptPrinter
1111
1212import Prelude.Compat hiding ((<>) )
1313
14- import Control.Arrow (second )
14+ import Control.Arrow (second , (>>>) )
1515
1616import Data.Maybe (maybe )
1717import Data.Text (Text )
@@ -104,16 +104,21 @@ prettyPrintValue d expr@BinaryNoParens{} = prettyPrintValueAtom d expr
104104prettyPrintValue d expr@ Parens {} = prettyPrintValueAtom d expr
105105prettyPrintValue d expr@ UnaryMinus {} = prettyPrintValueAtom d expr
106106
107+ prettyPrintQualifiedName :: (a -> Box ) -> Qualified a -> Box
108+ prettyPrintQualifiedName f (Qualified Nothing ident) = f ident
109+ prettyPrintQualifiedName f (Qualified (Just mod ) ident) = text (T. unpack $ runModuleName mod ) <> text " ." <> f ident
110+
111+
107112-- | Pretty-print an atomic expression, adding parentheses if necessary.
108113prettyPrintValueAtom :: Int -> Expr -> Box
109114prettyPrintValueAtom d (Literal _ l) = prettyPrintLiteralValue d l
110115prettyPrintValueAtom _ AnonymousArgument = text " _"
111- prettyPrintValueAtom _ (Constructor _ name) = text $ T. unpack $ runProperName (disqualify name)
112- prettyPrintValueAtom _ (Var _ ident) = text $ T. unpack $ showIdent (disqualify ident)
116+ prettyPrintValueAtom _ (Constructor _ name) = prettyPrintQualifiedName (runProperName >>> T. unpack >>> text) name
117+ prettyPrintValueAtom _ (Var _ ident) = prettyPrintQualifiedName (showIdent >>> T. unpack >>> text) ident
113118prettyPrintValueAtom d (BinaryNoParens op lhs rhs) =
114119 prettyPrintValue (d - 1 ) lhs `beforeWithSpace` printOp op `beforeWithSpace` prettyPrintValue (d - 1 ) rhs
115120 where
116- printOp (Op _ ( Qualified _ name)) = text $ T. unpack $ runOpName name
121+ printOp (Op _ name) = prettyPrintQualifiedName (runOpName >>> T. unpack >>> text) name
117122 printOp expr = text " `" <> prettyPrintValue (d - 1 ) expr `before` text " `"
118123prettyPrintValueAtom d (TypedValue _ val _) = prettyPrintValueAtom d val
119124prettyPrintValueAtom d (PositionedValue _ _ val) = prettyPrintValueAtom d val
0 commit comments