]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Machine.hs
test: dump splices using TH.runQ instead of calling ghc
[haskell/symantic-parser.git] / src / Symantic / Parser / Machine.hs
1 module Symantic.Parser.Machine
2 ( module Symantic.Parser.Machine
3 , module Symantic.Parser.Machine.Generate
4 , module Symantic.Parser.Machine.Input
5 , module Symantic.Parser.Machine.Instructions
6 , module Symantic.Parser.Machine.Optimize
7 , module Symantic.Parser.Machine.Program
8 , module Symantic.Parser.Machine.View
9 ) where
10 import Data.Function ((.))
11 import Data.Ord (Ord)
12 import System.IO (IO)
13 import Text.Show (Show)
14 import qualified Language.Haskell.TH.Syntax as TH
15
16 import Symantic.Parser.Grammar
17 import Symantic.Parser.Machine.Generate
18 import Symantic.Parser.Machine.Input
19 import Symantic.Parser.Machine.Instructions
20 import Symantic.Parser.Machine.Optimize
21 import Symantic.Parser.Machine.Program
22 import Symantic.Parser.Machine.View
23
24 -- * Type 'Parser'
25 type Parser inp = ParserRepr Gen inp
26
27 -- | Like a 'Parser' but not bound to the 'Gen' interpreter.
28 type ParserRepr repr inp =
29 ObserveSharing TH.Name
30 (OptimizeGrammar (Program repr inp))
31
32 -- | Build a 'Machine' able to 'generateCode' for the given 'Parser'.
33 machine :: forall inp repr a.
34 Ord (InputToken inp) =>
35 Show (InputToken inp) =>
36 TH.Lift (InputToken inp) =>
37 Grammar (InputToken inp) (Program repr inp) =>
38 Machine (InputToken inp) repr =>
39 ParserRepr repr inp a ->
40 IO (repr inp '[] a)
41 machine = optimizeMachine . grammar @(InputToken inp)