import Language.GenDSL as L
dsl :: QuasiQuoter
-dsl = QuasiQuoter
- { quoteExp = \s->location >>= parseExpr s
- , quotePat = undefined
- , quoteType = undefined
- , quoteDec = undefined
- }
+dsl = QuasiQuoter { quoteExp = parseDSL expr }
where
- parseExpr :: String -> Loc -> ExpQ
- parseExpr s loc = either (fail . show) id $ runParser p () file s
- where
- file = loc_filename loc
- (line, col) = loc_start loc
- p = getPosition >>= setPosition . mPos >> whiteSpace *> expr <* eof
- mPos p = setSourceName (setSourceLine (setSourceColumn p col) line) file
+ parseDSL :: Parser (Q e) -> String -> Q e
+ parseDSL ps s = do
+ loc <- location
+ let file = loc_filename loc
+ (line, col) = loc_start loc
+ p = getPosition >>= setPosition . mPos >> whiteSpace *> ps <* eof
+ mPos p = setSourceName (setSourceLine (setSourceColumn p col) line) file
+ either (fail . show) id $ runParser p () file s
-- Lexer
identifier,operator :: Parser String