diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-09-10 19:36:45 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-09-10 19:36:45 +0100 |
commit | c72455c9f4203ab7b9c617f26ffa7e5fdabf2d5f (patch) | |
tree | d3beadb7148c78123a777df9c82209882e7a0096 /src/Micro/Parser.hs | |
parent | 808f960c6aa800b0d3dcde897959a8e26303ef7d (diff) | |
download | micro-lang-hs-c72455c9f4203ab7b9c617f26ffa7e5fdabf2d5f.tar.gz micro-lang-hs-c72455c9f4203ab7b9c617f26ffa7e5fdabf2d5f.zip |
Revisited parser interface
Diffstat (limited to 'src/Micro/Parser.hs')
-rw-r--r-- | src/Micro/Parser.hs | 18 |
1 files changed, 13 insertions, 5 deletions
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 |