module Vulkan.Utils.ShaderQQ.HLSL
( hlsl
, insertLineDirective
) where
import Language.Haskell.TH
import Language.Haskell.TH.Quote
import Vulkan.Utils.Internal ( badQQ )
import Vulkan.Utils.ShaderQQ.Interpolate
hlsl :: QuasiQuoter
hlsl :: QuasiQuoter
hlsl = (String -> QuasiQuoter
badQQ String
"hlsl")
{ quoteExp :: String -> Q Exp
quoteExp = \String
s -> do
Loc
loc <- Q Loc
location
let codeWithLineDirective :: String
codeWithLineDirective = String -> Loc -> String
insertLineDirective String
s Loc
loc
String -> Q Exp
interpExp String
codeWithLineDirective
}
insertLineDirective :: String -> Loc -> String
insertLineDirective :: String -> Loc -> String
insertLineDirective String
code Loc {String
CharPos
loc_filename :: Loc -> String
loc_package :: Loc -> String
loc_module :: Loc -> String
loc_start :: Loc -> CharPos
loc_end :: Loc -> CharPos
loc_end :: CharPos
loc_start :: CharPos
loc_module :: String
loc_package :: String
loc_filename :: String
..} =
let lineDirective :: String
lineDirective =
String
"#line " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show (CharPos -> Int
forall a b. (a, b) -> a
fst CharPos
loc_start) String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" \"" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
loc_filename String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\""
in String
lineDirective String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
code