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.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
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
21 import Control.DeepSeq (NFData)
22 import Data.Eq (Eq(..))
23 import Data.Function ((.))
24 import Data.String (String)
25 import Data.Typeable (Typeable)
26 import Text.Show (Show(..))
27 import qualified Language.Haskell.TH.Syntax as TH
29 -- * Class 'Grammarable'
30 type Grammarable tok repr =
34 , Letable TH.Name repr
35 , Letsable TH.Name repr
38 , CombSatisfiable tok repr
47 -- | A usual pipeline to interpret 'Comb'inators:
48 -- 'observeSharing' then 'optimizeGrammar' then a polymorphic @(repr)@.
50 Grammarable tok repr =>
51 ObserveSharing TH.Name
52 (OptimizeGrammar repr) a ->
54 grammar = optimizeGrammar . observeSharing
56 -- | An usual pipeline to show 'Comb'inators:
57 -- 'observeSharing' then 'optimizeGrammar' then 'viewGrammar' then 'show'.
58 showGrammar :: forall showName a tok repr.
59 repr ~ ObserveSharing TH.Name (OptimizeGrammar (ViewGrammar showName)) =>
60 ShowLetName showName TH.Name =>
61 Grammarable tok repr =>
63 showGrammar = show . viewGrammar . grammar @tok