]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Grammar.hs
Reorganize Comb and Instr optimizations
[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 ) where
13 import Symantic.Parser.Grammar.Combinators
14 import Symantic.Parser.Grammar.View
15 import Symantic.Parser.Grammar.Fixity
16 import Symantic.Parser.Grammar.ObserveSharing
17 import Symantic.Parser.Grammar.Optimize
18 import Symantic.Parser.Grammar.Write
19 import Symantic.Univariant.Letable (Letable(..))
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 , Selectable repr
33 , Matchable repr
34 , Foldable repr
35 , Lookable repr
36 )
37
38 -- | A usual pipeline to interpret 'Comb'inators:
39 -- 'observeSharing' then 'optimizeGrammar' then a polymorphic @(repr)@.
40 grammar :: Grammar tok repr => ObserveSharing TH.Name (OptimizeGrammar repr) a -> repr a
41 grammar = optimizeGrammar . observeSharing
42
43 -- | A usual pipeline to show 'Comb'inators:
44 -- 'observeSharing' then 'optimizeGrammar' then 'viewGrammar' then 'show'.
45 showGrammar :: ObserveSharing TH.Name (OptimizeGrammar ViewGrammar) a -> String
46 showGrammar = show . viewGrammar . optimizeGrammar . observeSharing