From c72455c9f4203ab7b9c617f26ffa7e5fdabf2d5f Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 10 Sep 2022 19:36:45 +0100 Subject: Revisited parser interface --- src/Micro/Parser.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/Micro') diff --git a/src/Micro/Parser.hs b/src/Micro/Parser.hs index ea4873e..45ba44d 100644 --- a/src/Micro/Parser.hs +++ b/src/Micro/Parser.hs @@ -1,4 +1,9 @@ -module Micro.Parser where +module Micro.Parser + ( Micro.Parser.parse, + parseFromFile, + parseFromString, + ) +where import Control.Monad.Identity (Identity) import Data.Maybe (isJust) @@ -217,7 +222,10 @@ program = do parse :: Parser [Expr] parse = program -parseFromFile :: Parsec String () a -> FilePath -> IO (Either ParseError a) -parseFromFile p fname = do - input <- readFile fname - return (runParser p () fname input) +parseFromFile :: FilePath -> IO (Either ParseError [Expr]) +parseFromFile filename = do + input <- readFile filename + return $ runParser (scan Micro.Parser.parse) () filename input + +parseFromString :: String -> Either ParseError [Expr] +parseFromString input = runParser (scan Micro.Parser.parse) () "-" input -- cgit v1.2.3