]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Grammar.hs
add registers
[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 System.IO (IO)
28 import Text.Show (Show(..))
29 import qualified Data.Functor as Functor
30 import qualified Language.Haskell.TH.Syntax as TH
31
32 -- * Type 'Grammar'
33 type Grammar repr = ObserveSharing TH.Name (OptimizeGrammar repr)
34
35 -- ** Class 'Grammarable'
36 type Grammarable tok repr =
37 ( CombAlternable repr
38 , CombApplicable repr
39 , CombFoldable repr
40 , Referenceable TH.Name repr
41 , Letsable TH.Name repr
42 , CombLookable repr
43 , CombMatchable repr
44 , CombSatisfiable tok repr
45 , CombSelectable repr
46 --, CombRegisterable repr
47 , CombRegisterableUnscoped repr
48 , Eq tok
49 , Ord tok
50 , TH.Lift tok
51 , NFData tok
52 , Show tok
53 , Typeable tok
54 )
55
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
60
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