Skip to content

Commit 39c216f

Browse files
committed
Print Qualified names correctly
1 parent 5b32976 commit 39c216f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Purepur/PurescriptPrinter.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Purepur.PurescriptPrinter
1111

1212
import Prelude.Compat hiding ((<>))
1313

14-
import Control.Arrow (second)
14+
import Control.Arrow (second, (>>>))
1515

1616
import Data.Maybe (maybe)
1717
import Data.Text (Text)
@@ -104,16 +104,21 @@ prettyPrintValue d expr@BinaryNoParens{} = prettyPrintValueAtom d expr
104104
prettyPrintValue d expr@Parens{} = prettyPrintValueAtom d expr
105105
prettyPrintValue 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.
108113
prettyPrintValueAtom :: Int -> Expr -> Box
109114
prettyPrintValueAtom d (Literal _ l) = prettyPrintLiteralValue d l
110115
prettyPrintValueAtom _ 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
113118
prettyPrintValueAtom 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 "`"
118123
prettyPrintValueAtom d (TypedValue _ val _) = prettyPrintValueAtom d val
119124
prettyPrintValueAtom d (PositionedValue _ _ val) = prettyPrintValueAtom d val

0 commit comments

Comments
 (0)