]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Grammar.hs
Fix infinite loop in observeSharing
[haskell/symantic-parser.git] / src / Symantic / Parser / Grammar.hs
1 {-# LANGUAGE ConstraintKinds #-}
2 module Symantic.Parser.Grammar
3 ( module Symantic.Parser.Grammar
4 , module Symantic.Parser.Grammar.Combinators
5 , module Symantic.Parser.Grammar.Optimize
6 , module Symantic.Parser.Grammar.ObserveSharing
7 , module Symantic.Parser.Grammar.Write
8 , module Symantic.Parser.Grammar.Dump
9 , Letable(..)
10 ) where
11 import Symantic.Parser.Grammar.Combinators
12 import Symantic.Parser.Grammar.Optimize
13 import Symantic.Parser.Grammar.ObserveSharing
14 import Symantic.Parser.Grammar.Write
15 import Symantic.Parser.Grammar.Dump
16 import Symantic.Univariant.Letable (Letable(..))
17
18 import Data.Function ((.))
19 import Data.String (String)
20 import Text.Show (Show(..))
21 import qualified Language.Haskell.TH.Syntax as TH
22
23 -- Class 'Grammar'
24 type Grammar repr =
25 ( Applicable repr
26 , Alternable repr
27 , Charable repr
28 , Letable TH.Name repr
29 , Selectable repr
30 , Matchable repr
31 , Foldable repr
32 , Lookable repr
33 )
34
35 -- | A usual pipeline to interpret 'Comb'inators:
36 -- 'observeSharing' then 'optimizeComb' then a polymorphic @(repr)@.
37 grammar :: Grammar repr => ObserveSharing TH.Name (OptimizeComb TH.Name repr) a -> repr a
38 grammar = optimizeComb . observeSharing
39
40 -- | A usual pipeline to show 'Comb'inators:
41 -- 'observeSharing' then 'optimizeComb' then 'dumpComb' then 'show'.
42 showGrammar :: ObserveSharing TH.Name (OptimizeComb TH.Name DumpComb) a -> String
43 showGrammar = show . dumpComb . optimizeComb . observeSharing