on master help sign in
Implement rendering of ‘HsTypedSplice’ and ‘HsUntypedSplice’
f9c58afwaddlaw
data/examples/declaration/value/function/n-plus-k-pattern-out.hs → data/examples/declaration/value/function/pattern/n-plus-k-pattern-out.hsrenamed

The content is the same.

data/examples/declaration/value/function/n-plus-k-pattern.hs → data/examples/declaration/value/function/pattern/n-plus-k-pattern.hsrenamed

The content is the same.

data/examples/declaration/value/function/pattern-bind-out.hs → data/examples/declaration/value/function/pattern/pattern-bind-out.hsrenamed

The content is the same.

data/examples/declaration/value/function/pattern-bind.hs → data/examples/declaration/value/function/pattern/pattern-bind.hsrenamed

The content is the same.

data/examples/declaration/value/function/quasi-quotes-pattern-out.hs → data/examples/declaration/value/function/pattern/quasi-quotes-pattern-out.hsrenamed

The content is the same.

data/examples/declaration/value/function/quasi-quotes-pattern.hs → data/examples/declaration/value/function/pattern/quasi-quotes-pattern.hsrenamed

The content is the same.

data/examples/declaration/value/function/record-patterns-out.hs → data/examples/declaration/value/function/pattern/record-patterns-out.hsrenamed

The content is the same.

data/examples/declaration/value/function/record-patterns.hs → data/examples/declaration/value/function/pattern/record-patterns.hsrenamed

The content is the same.

data/examples/declaration/value/function/sig-pattern-out.hs → data/examples/declaration/value/function/pattern/sig-pattern-out.hsrenamed

The content is the same.

data/examples/declaration/value/function/sig-pattern.hs → data/examples/declaration/value/function/pattern/sig-pattern.hsrenamed

The content is the same.

data/examples/declaration/value/function/pattern/splice-pattern-out.hsnew file+12
@@ -0,0 +1,12 @@
1+{-# LANGUAGE TemplateHaskell #-}
2+singleLine = case () of
3+ $x -> ()
4+ $(y "something") -> ()
5+
6+multiline = case () of
7+ $( x +
8+ y
9+ ) -> ()
10+ $( y
11+ "something'"
12+ ) -> ()
data/examples/declaration/value/function/pattern/splice-pattern.hsnew file+11
@@ -0,0 +1,11 @@
1+{-# LANGUAGE TemplateHaskell #-}
2+
3+singleLine = case () of
4+ $x -> ()
5+ $(y "something") -> ()
6+
7+multiline = case () of
8+ $(x
9+ + y) -> ()
10+ $(y
11+ "something'") -> ()
data/examples/declaration/value/function/view-pattern-out.hs → data/examples/declaration/value/function/pattern/view-pattern-out.hsrenamed

The content is the same.

data/examples/declaration/value/function/view-pattern.hs → data/examples/declaration/value/function/pattern/view-pattern.hsrenamed

The content is the same.

data/examples/declaration/value/function/splice-out.hsnew file+8
@@ -0,0 +1,8 @@
1+{-# LANGUAGE TemplateHaskell #-}
2+bar = $bar
3+
4+bar' = $(bar "something")
5+
6+baz = $$baz
7+
8+baz' = $$(baz "something")
data/examples/declaration/value/function/splice.hsnew file+9
@@ -0,0 +1,9 @@
1+{-# LANGUAGE TemplateHaskell #-}
2+
3+bar = $bar
4+
5+bar' = $(bar "something")
6+
7+baz = $$baz
8+
9+baz' = $$(baz "something")
src/Ormolu/Printer/Meat/Declaration/Value.hs+19−2
@@ -541,8 +541,8 @@ p_pat_hsRecField HsRecField {..} = do
541
541
542p_hsSplice :: HsSplice GhcPs -> R ()
542p_hsSplice :: HsSplice GhcPs -> R ()
543p_hsSplice = \case
543p_hsSplice = \case
544− HsTypedSplice {} -> notImplemented "HsTypedSplice"
544+ HsTypedSplice NoExt deco _ expr -> p_hsSpliceTH True expr deco
545− HsUntypedSplice {} -> notImplemented "HsUntypedSplice"
545+ HsUntypedSplice NoExt deco _ expr -> p_hsSpliceTH False expr deco
546 HsQuasiQuote NoExt _ quoterName srcSpan str -> do
546 HsQuasiQuote NoExt _ quoterName srcSpan str -> do
547 let locatedQuoterName = L srcSpan quoterName
547 let locatedQuoterName = L srcSpan quoterName
548 p_quasiQuote locatedQuoterName $ do
548 p_quasiQuote locatedQuoterName $ do
@@ -551,6 +551,23 @@ p_hsSplice = \case
551 HsSpliced {} -> notImplemented "HsSpliced"
551 HsSpliced {} -> notImplemented "HsSpliced"
552 XSplice {} -> notImplemented "XSplice"
552 XSplice {} -> notImplemented "XSplice"
553
553
554+p_hsSpliceTH
555+ :: Bool -- ^ Typed splice?
556+ -> LHsExpr GhcPs -- ^ Splice expression
557+ -> SpliceDecoration -- ^ Splice decoration
558+ -> R ()
559+p_hsSpliceTH isTyped expr = \case
560+ HasParens -> do
561+ txt decoSymbol
562+ parens (located expr p_hsExpr)
563+ HasDollar -> do
564+ txt decoSymbol
565+ located expr p_hsExpr
566+ NoParens -> do
567+ located expr p_hsExpr
568+ where
569+ decoSymbol = if isTyped then "$$" else "$"
570+
554p_quasiQuote :: Located RdrName -> R () -> R ()
571p_quasiQuote :: Located RdrName -> R () -> R ()
555p_quasiQuote quoter m = do
572p_quasiQuote quoter m = do
556 txt "["
573 txt "["