]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Automaton.hs
Add runParser
[haskell/symantic-parser.git] / src / Symantic / Parser / Automaton.hs
1 {-# LANGUAGE TemplateHaskell #-}
2 module Symantic.Parser.Automaton
3 ( module Symantic.Parser.Automaton
4 , module Symantic.Parser.Automaton.Instructions
5 , module Symantic.Parser.Automaton.Dump
6 , module Symantic.Parser.Automaton.Eval
7 , module Symantic.Parser.Automaton.Input
8 ) where
9 import Symantic.Parser.Automaton.Instructions
10 import Symantic.Parser.Automaton.Dump
11 import Symantic.Parser.Automaton.Eval
12 import Data.Either (Either(..))
13
14 import Symantic.Parser.Grammar
15 import Symantic.Parser.Automaton.Input
16 import Data.Function ((.))
17 import Language.Haskell.TH (CodeQ)
18 import qualified Language.Haskell.TH.Syntax as TH
19
20 type Parser inp =
21 ObserveSharing TH.Name
22 (OptimizeComb TH.Name
23 (Automaton inp))
24
25 automaton :: forall inp repr a.
26 Executable repr =>
27 Grammar (Automaton inp) =>
28 Parser inp a ->
29 repr inp '[] ('Succ 'Zero) a
30 automaton = runAutomaton . optimizeComb . observeSharing
31
32 runParser :: forall inp a.
33 Input inp =>
34 Parser (Cursor inp) a ->
35 CodeQ (inp -> Either ParsingError a)
36 runParser p = [||\input -> $$(eval [||input||] (automaton p))||]