module Text.Docvim.Util ( compileUnits
, p
, parseUnit
, pm
, pp
, ppm
, ppv
, pv
) where
import Text.Docvim.AST
import Text.Docvim.Compile
import Text.Docvim.Parse
import Text.Docvim.Printer.Markdown
import Text.Docvim.Printer.Vim
import Text.Parsec
import Text.Show.Pretty
parseUnit :: String -> Either ParseError Node
parseUnit = runParser unit () "(eval)"
compileUnits :: [String] -> Either ParseError Node
compileUnits inputs = do
parsed <- mapM parseUnit inputs
return $ compile parsed
p :: [String] -> String
p inputs = case compileUnits inputs of
Left err -> show err
Right ast -> ppShow ast
pp :: String -> IO ()
pp input = putStrLn $ p [input]
pv :: [String] -> String
pv inputs = case compileUnits inputs of
Left err -> show err
Right ast -> vimHelp ast
ppv :: String -> IO ()
ppv input = putStr $ pv [input]
pm :: [String] -> String
pm inputs = case compileUnits inputs of
Left err -> show err
Right ast -> markdown ast
ppm :: String -> IO ()
ppm input = putStr $ pm [input]