]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Grammar.hs
change ShowLetName into HideableName
[haskell/symantic-parser.git] / src / Symantic / Parser / Grammar.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-} -- For grammar
2 {-# LANGUAGE ConstraintKinds #-} -- For Grammarable
3 module Symantic.Parser.Grammar
4 ( module Symantic.Parser.Grammar
5 , module Symantic.Parser.Grammar.Combinators
6 , module Symantic.Parser.Grammar.Optimize
7 , module Symantic.Parser.Grammar.ObserveSharing
8 , module Symantic.Parser.Grammar.Production
9 , module Symantic.Parser.Grammar.Write
10 , module Symantic.Parser.Grammar.View
11 , Referenceable(..)
12 , Letsable(..)
13 ) where
14 import Symantic.Parser.Grammar.Combinators
15 import Symantic.Parser.Grammar.ObserveSharing
16 import Symantic.Parser.Grammar.Optimize
17 import Symantic.Parser.Grammar.Production
18 import Symantic.Parser.Grammar.View
19 import Symantic.Parser.Grammar.Write
20
21 import Control.DeepSeq (NFData)
22 import Data.Eq (Eq)
23 import Data.Ord (Ord)
24 import Data.Function ((.))
25 import Data.String (String)
26 import Data.Typeable (Typeable)
27 import Text.Show (Show(..))
28 import Language.Haskell.TH.HideName
29 import qualified Language.Haskell.TH.Syntax as TH
30
31 -- * Type 'Grammar'
32 type Grammar repr = ObserveSharing TH.Name (OptimizeGrammar repr)
33
34 -- ** Class 'Grammarable'
35 type Grammarable tok repr =
36 ( CombAlternable repr
37 , CombApplicable repr
38 , CombFoldable repr
39 , Referenceable TH.Name repr
40 , Letsable TH.Name repr
41 , CombLookable repr
42 , CombMatchable repr
43 , CombSatisfiable tok repr
44 , CombSelectable repr
45 --, CombRegisterable repr
46 , CombRegisterableUnscoped repr
47 , Eq tok
48 , Ord tok
49 , TH.Lift tok
50 , NFData tok
51 , Show tok
52 , Typeable tok
53 )
54
55 -- | A usual pipeline to interpret 'Comb'inators:
56 -- 'observeSharing' then 'optimizeGrammar' then a polymorphic @(repr)@.
57 grammar :: Grammarable tok repr => Grammar repr a -> repr a
58 grammar = optimizeGrammar . observeSharing
59
60 -- | An usual pipeline to show 'Comb'inators:
61 -- 'observeSharing' then 'optimizeGrammar' then 'viewGrammar' then 'show'.
62 showGrammar :: forall showName a tok.
63 HideableName showName =>
64 Grammarable tok (Grammar (ViewGrammar showName)) =>
65 Grammar (ViewGrammar showName) a -> String
66 showGrammar = show . viewGrammar . grammar @tok