mirror of
https://github.com/google/ormolu.git
synced 2025-01-07 15:50:27 +03:00
Implement rendering of ‘HsTypedSplice’ and ‘HsUntypedSplice’
This commit is contained in:
parent
2c6a9829ab
commit
f9c58af594
@ -0,0 +1,12 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
singleLine = case () of
|
||||
$x -> ()
|
||||
$(y "something") -> ()
|
||||
|
||||
multiline = case () of
|
||||
$( x +
|
||||
y
|
||||
) -> ()
|
||||
$( y
|
||||
"something'"
|
||||
) -> ()
|
@ -0,0 +1,11 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
singleLine = case () of
|
||||
$x -> ()
|
||||
$(y "something") -> ()
|
||||
|
||||
multiline = case () of
|
||||
$(x
|
||||
+ y) -> ()
|
||||
$(y
|
||||
"something'") -> ()
|
8
data/examples/declaration/value/function/splice-out.hs
Normal file
8
data/examples/declaration/value/function/splice-out.hs
Normal file
@ -0,0 +1,8 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
bar = $bar
|
||||
|
||||
bar' = $(bar "something")
|
||||
|
||||
baz = $$baz
|
||||
|
||||
baz' = $$(baz "something")
|
9
data/examples/declaration/value/function/splice.hs
Normal file
9
data/examples/declaration/value/function/splice.hs
Normal file
@ -0,0 +1,9 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
bar = $bar
|
||||
|
||||
bar' = $(bar "something")
|
||||
|
||||
baz = $$baz
|
||||
|
||||
baz' = $$(baz "something")
|
@ -541,8 +541,8 @@ p_pat_hsRecField HsRecField {..} = do
|
||||
|
||||
p_hsSplice :: HsSplice GhcPs -> R ()
|
||||
p_hsSplice = \case
|
||||
HsTypedSplice {} -> notImplemented "HsTypedSplice"
|
||||
HsUntypedSplice {} -> notImplemented "HsUntypedSplice"
|
||||
HsTypedSplice NoExt deco _ expr -> p_hsSpliceTH True expr deco
|
||||
HsUntypedSplice NoExt deco _ expr -> p_hsSpliceTH False expr deco
|
||||
HsQuasiQuote NoExt _ quoterName srcSpan str -> do
|
||||
let locatedQuoterName = L srcSpan quoterName
|
||||
p_quasiQuote locatedQuoterName $ do
|
||||
@ -551,6 +551,23 @@ p_hsSplice = \case
|
||||
HsSpliced {} -> notImplemented "HsSpliced"
|
||||
XSplice {} -> notImplemented "XSplice"
|
||||
|
||||
p_hsSpliceTH
|
||||
:: Bool -- ^ Typed splice?
|
||||
-> LHsExpr GhcPs -- ^ Splice expression
|
||||
-> SpliceDecoration -- ^ Splice decoration
|
||||
-> R ()
|
||||
p_hsSpliceTH isTyped expr = \case
|
||||
HasParens -> do
|
||||
txt decoSymbol
|
||||
parens (located expr p_hsExpr)
|
||||
HasDollar -> do
|
||||
txt decoSymbol
|
||||
located expr p_hsExpr
|
||||
NoParens -> do
|
||||
located expr p_hsExpr
|
||||
where
|
||||
decoSymbol = if isTyped then "$$" else "$"
|
||||
|
||||
p_quasiQuote :: Located RdrName -> R () -> R ()
|
||||
p_quasiQuote quoter m = do
|
||||
txt "["
|
||||
|
Loading…
Reference in New Issue
Block a user