forked from j-mie6/ParsleyHaskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParsley.hs
31 lines (27 loc) · 1.14 KB
/
Parsley.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Parsley (
module Parsley,
module Core,
module Primitives,
module Applicative,
module Alternative,
module Selective,
module Combinator,
module Fold,
module THUtils,
) where
import Prelude hiding (readFile)
import Data.Text.IO (readFile)
import Parsley.Backend (codeGen, Input, eval, prepare)
import Parsley.Frontend (compile)
import Parsley.Alternative as Alternative
import Parsley.Applicative as Applicative
import Parsley.Core as Core
import Parsley.Combinator as Combinator (item, char, string, satisfy, notFollowedBy, lookAhead, try)
import Parsley.Common.Utils as THUtils (code, Quapplicative(..), WQ, Code)
import Parsley.Fold as Fold (many, some)
import Parsley.Selective as Selective
import Parsley.Core.Primitives as Primitives (debug)
runParser :: Input input => Parser a -> Code (input -> Maybe a)
runParser p = [||\input -> $$(eval (prepare [||input||]) (compile p codeGen))||]
parseFromFile :: Parser a -> Code (FilePath -> IO (Maybe a))
parseFromFile p = [||\filename -> do input <- readFile filename; return ($$(runParser p) (Text16 input))||]