]> Git — Sourcephile - haskell/symantic-parser.git/blob - src/Symantic/Parser/Grammar.hs
Rename many things and continue Instr interpretation
[haskell/symantic-parser.git] / src / Symantic / Parser / Grammar.hs
1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
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.Write
9 , module Symantic.Parser.Grammar.Dump
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 System.IO (IO)
21 import Text.Show (Show(..))
22 import qualified Data.Functor as Functor
23 import qualified Language.Haskell.TH.Syntax as TH
24
25 -- Class 'Grammar'
26 type Grammar repr =
27 ( Applicable repr
28 , Alternable repr
29 , Charable repr
30 , Letable TH.Name repr
31 , Selectable repr
32 , Matchable repr
33 , Foldable repr
34 , Lookable repr
35 )
36
37 -- | A usual pipeline to show 'Comb'inators: 'observeSharing' then 'optimizeComb' then 'dumpComb' then 'show'.
38 -- Note that the 'IO' is required to 'observeSharing' which is required to avoid an infinite recursion when generating.
39 grammar = (optimizeComb Functor.<$>) . observeSharing
40
41 -- | A usual pipeline to show 'Comb'inators: 'observeSharing' then 'optimizeComb' then 'dumpComb' then 'show'.
42 -- Note that the 'IO' is required to 'observeSharing' which is required to avoid an infinite recursion when the grammar is recursive.
43 showGrammar :: ObserveSharing TH.Name (OptimizeComb TH.Name DumpComb) a -> IO String
44 showGrammar = (show . dumpComb . optimizeComb Functor.<$>) . observeSharing