{-#OPTIONS_GHC -fno-warn-missing-fields#-}
module Text.Alex.Quote (
parseAlex
, compileAlex
, Alex
, alex
) where
import Text.Alex(runAlex, Target(..), CLIFlags(..))
import Text.Alex.AlexTemplate
import Language.Haskell.TH.Quote
import Language.Haskell.TH
import Language.Haskell.Meta
type Alex = String
compileAlex :: Alex -> Q [Dec]
compileAlex :: Alex -> Q [Dec]
compileAlex = [Dec] -> Q [Dec]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Dec] -> Q [Dec]) -> (Alex -> [Dec]) -> Alex -> Q [Dec]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Alex -> [Dec]) -> ([Dec] -> [Dec]) -> Either Alex [Dec] -> [Dec]
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Alex -> [Dec]
forall a. HasCallStack => Alex -> a
error [Dec] -> [Dec]
forall a. a -> a
id (Either Alex [Dec] -> [Dec])
-> (Alex -> Either Alex [Dec]) -> Alex -> [Dec]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Alex -> Either Alex [Dec]
parseDecs
alex :: QuasiQuoter
alex :: QuasiQuoter
alex = QuasiQuoter :: (Alex -> Q Exp)
-> (Alex -> Q Pat)
-> (Alex -> Q Type)
-> (Alex -> Q [Dec])
-> QuasiQuoter
QuasiQuoter {quoteExp :: Alex -> Q Exp
quoteExp = Lit -> Q Exp
litE (Lit -> Q Exp) -> (Alex -> Lit) -> Alex -> Q Exp
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Alex -> Lit
StringL (Alex -> Lit) -> (Alex -> Alex) -> Alex -> Lit
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Alex -> Alex
parseAlex}
parseAlex :: String -> Alex
parseAlex :: Alex -> Alex
parseAlex Alex
s = (Alex, Alex) -> Alex
forall a b. (a, b) -> a
fst ([CLIFlags] -> Maybe Alex -> Alex -> (Alex, Alex)
runAlex [] Maybe Alex
forall a. Maybe a
Nothing Alex
s) Alex -> Alex -> Alex
forall a. [a] -> [a] -> [a]
++ Alex
"\n" Alex -> Alex -> Alex
forall a. [a] -> [a] -> [a]
++ Target -> Alex
forall p. p -> Alex
alexTemplate Target
HaskellTarget