]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Grammar.hs
test: dump splices using TH.runQ instead of calling ghc
[haskell/symantic-parser.git] / src / Symantic / Parser / Grammar.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-} -- For grammar
2 {-# LANGUAGE ConstraintKinds #-} -- For Grammar
3 module Symantic.Parser.Grammar
4 ( module Symantic.Parser.Grammar
5 , module Symantic.Parser.Grammar.Combinators
6 , module Symantic.Parser.Grammar.Fixity
7 , module Symantic.Parser.Grammar.Optimize
8 , module Symantic.Parser.Grammar.ObserveSharing
9 , module Symantic.Parser.Grammar.Write
10 , module Symantic.Parser.Grammar.View
11 , Letable(..)
12 , Letsable(..)
13 ) where
14 import Symantic.Parser.Grammar.Combinators
15 import Symantic.Parser.Grammar.View
16 import Symantic.Parser.Grammar.Fixity
17 import Symantic.Parser.Grammar.ObserveSharing
18 import Symantic.Parser.Grammar.Optimize
19 import Symantic.Parser.Grammar.Write
20
21 import Data.Function ((.))
22 import Data.String (String)
23 import Text.Show (Show(..))
24 import qualified Language.Haskell.TH.Syntax as TH
25
26 -- * Class 'Grammar'
27 type Grammar tok repr =
28 ( Applicable repr
29 , Alternable repr
30 , Satisfiable tok repr
31 , Letable TH.Name repr
32 , Letsable TH.Name repr
33 , Selectable repr
34 , Matchable repr
35 , Foldable repr
36 , Lookable repr
37 )
38
39 -- | A usual pipeline to interpret 'Comb'inators:
40 -- 'observeSharing' then 'optimizeGrammar' then a polymorphic @(repr)@.
41 grammar ::
42 Grammar tok repr =>
43 ObserveSharing TH.Name
44 (OptimizeGrammar repr) a ->
45 repr a
46 grammar = optimizeGrammar . observeSharing
47
48 -- | An usual pipeline to show 'Comb'inators:
49 -- 'observeSharing' then 'optimizeGrammar' then 'viewGrammar' then 'show'.
50 showGrammar ::
51 ShowLetName showName TH.Name =>
52 ObserveSharing TH.Name
53 (OptimizeGrammar (ViewGrammar showName)) a ->
54 String
55 showGrammar = show . viewGrammar . grammar