Implement rendering of ‘HsTypedSplice’ and ‘HsUntypedSplice’

This commit is contained in:
waddlaw 2019-06-16 16:11:04 +09:00 committed by Mark Karpov
parent 2c6a9829ab
commit f9c58af594
17 changed files with 59 additions and 2 deletions

View File

@ -0,0 +1,12 @@
{-# LANGUAGE TemplateHaskell #-}
singleLine = case () of
$x -> ()
$(y "something") -> ()
multiline = case () of
$( x +
y
) -> ()
$( y
"something'"
) -> ()

View File

@ -0,0 +1,11 @@
{-# LANGUAGE TemplateHaskell #-}
singleLine = case () of
$x -> ()
$(y "something") -> ()
multiline = case () of
$(x
+ y) -> ()
$(y
"something'") -> ()

View File

@ -0,0 +1,8 @@
{-# LANGUAGE TemplateHaskell #-}
bar = $bar
bar' = $(bar "something")
baz = $$baz
baz' = $$(baz "something")

View File

@ -0,0 +1,9 @@
{-# LANGUAGE TemplateHaskell #-}
bar = $bar
bar' = $(bar "something")
baz = $$baz
baz' = $$(baz "something")

View File

@ -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 "["