module Text.Webrexp.Quote ( webrexpParse
, webrexpCompile ) where
import Language.Haskell.TH
import Language.Haskell.TH.Quote
import Language.Haskell.TH.Syntax
import Text.Webrexp
import Text.Webrexp.WebRexpAutomata
webrexpParse :: QuasiQuoter
webrexpParse = QuasiQuoter
{ quoteExp = parser
, quotePat = undefined
, quoteType = undefined
, quoteDec = undefined
}
parser :: String -> Q Exp
parser s = case parseWebRexp s of
Nothing -> fail "Invalid webrexp syntax"
Just w -> lift w
webrexpCompile :: QuasiQuoter
webrexpCompile = QuasiQuoter
{ quoteExp = compiler
, quotePat = undefined
, quoteType = undefined
, quoteDec = undefined
}
compiler :: String -> Q Exp
compiler s = case parseWebRexp s of
Nothing -> fail "Invalid webrexp syntax"
Just w -> lift $ buildAutomata w