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
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
21 import Control.DeepSeq (NFData)
24 import Data.Function ((.))
25 import Data.String (String)
26 import Data.Typeable (Typeable)
28 import Text.Show (Show(..))
29 import qualified Data.Functor as Functor
30 import qualified Language.Haskell.TH.Syntax as TH
33 type Grammar repr = ObserveSharing TH.Name (OptimizeGrammar repr)
35 -- ** Class 'Grammarable'
36 type Grammarable tok repr =
40 , Referenceable TH.Name repr
41 , Letsable TH.Name repr
44 , CombSatisfiable tok repr
46 --, CombRegisterable repr
47 , CombRegisterableUnscoped repr
56 -- | A usual pipeline to interpret 'Comb'inators:
57 -- 'observeSharing' then 'optimizeGrammar' then a polymorphic @(repr)@.
58 grammar :: Grammarable tok repr => Grammar repr a -> repr a
59 grammar = optimizeGrammar . observeSharing
61 -- | An usual pipeline to show 'Comb'inators:
62 -- 'observeSharing' then 'optimizeGrammar' then 'viewGrammar' then 'show'.
63 showGrammar :: forall showName a tok.
64 ShowLetName showName TH.Name =>
65 Grammarable tok (Grammar (ViewGrammar showName)) =>
66 Grammar (ViewGrammar showName) a -> String
67 showGrammar = show . viewGrammar . grammar @tok