]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Grammar.hs
machine: normalOrderReduction at the last moment
[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 qualified Language.Haskell.TH.Syntax as TH
29
30 -- * Type 'Grammar'
31 type Grammar repr = ObserveSharing TH.Name (OptimizeGrammar repr)
32
33 -- ** Class 'Grammarable'
34 type Grammarable tok repr =
35 ( CombAlternable repr
36 , CombApplicable repr
37 , CombFoldable repr
38 , Referenceable TH.Name repr
39 , Letsable TH.Name repr
40 , CombLookable repr
41 , CombMatchable repr
42 , CombSatisfiable tok repr
43 , CombSelectable repr
44 --, CombRegisterable repr
45 , CombRegisterableUnscoped repr
46 , Eq tok
47 , Ord tok
48 , TH.Lift tok
49 , NFData tok
50 , Show tok
51 , Typeable tok
52 )
53
54 -- | A usual pipeline to interpret 'Comb'inators:
55 -- 'observeSharing' then 'optimizeGrammar' then a polymorphic @(repr)@.
56 grammar :: Grammarable tok repr => Grammar repr a -> repr a
57 grammar = optimizeGrammar . observeSharing
58
59 -- | An usual pipeline to show 'Comb'inators:
60 -- 'observeSharing' then 'optimizeGrammar' then 'viewGrammar' then 'show'.
61 showGrammar :: forall showName a tok.
62 ShowLetName showName TH.Name =>
63 Grammarable tok (Grammar (ViewGrammar showName)) =>
64 Grammar (ViewGrammar showName) a -> String
65 showGrammar = show . viewGrammar . grammar @tok