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.SharingObserver
8 , module Symantic.Parser.Grammar.Production
9 , module Symantic.Parser.Grammar.Write
10 , module Symantic.Parser.Grammar.View
14 import Symantic.Parser.Grammar.Combinators
15 import Symantic.Parser.Grammar.SharingObserver
16 import Symantic.Parser.Grammar.Optimize
17 import Symantic.Parser.Grammar.Production
18 import Symantic.Parser.Grammar.View
19 import Symantic.Parser.Grammar.Write
21 import Control.DeepSeq (NFData)
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
32 type Grammar repr = SharingObserver TH.Name (OptimizeGrammar repr)
34 -- ** Class 'Grammarable'
35 type Grammarable tok repr =
39 , Referenceable TH.Name repr
40 , Letsable TH.Name repr
43 , CombSatisfiable tok repr
45 --, CombRegisterable repr
46 , CombRegisterableUnscoped repr
55 -- | A usual pipeline to interpret 'Comb'inators:
56 -- 'sharingObserver' then 'optimizeGrammar' then a polymorphic @(repr)@.
57 grammar :: Grammarable tok repr => Grammar repr a -> repr a
58 grammar = optimizeGrammar . sharingObserver
60 -- | An usual pipeline to show 'Comb'inators:
61 -- 'sharingObserver' 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