]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Grammar.hs
test: hide unique names for reproductibility
[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
20 import Data.Function ((.))
21 import Data.String (String)
22 import Text.Show (Show(..))
23 import qualified Language.Haskell.TH.Syntax as TH
24
25 -- * Class 'Grammar'
26 type Grammar tok repr =
27 ( Applicable repr
28 , Alternable repr
29 , Satisfiable tok repr
30 , Letable TH.Name repr
31 , Selectable repr
32 , Matchable repr
33 , Foldable repr
34 , Lookable repr
35 )
36
37 -- | A usual pipeline to interpret 'Comb'inators:
38 -- 'observeSharing' then 'optimizeGrammar' then a polymorphic @(repr)@.
39 grammar ::
40 Grammar tok repr =>
41 ObserveSharing TH.Name
42 (OptimizeGrammar repr) a ->
43 repr a
44 grammar = optimizeGrammar . observeSharing
45
46 -- | An usual pipeline to show 'Comb'inators:
47 -- 'observeSharing' then 'optimizeGrammar' then 'viewGrammar' then 'show'.
48 showGrammar ::
49 ObserveSharing TH.Name
50 (OptimizeGrammar (ViewGrammar showName)) a ->
51 String
52 showGrammar = show . viewGrammar . optimizeGrammar . observeSharing