-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An interface to create production rules using augmented grammars -- -- This package allows you to define production rules using clean -- augmented grammars. @package parser241 @version 0.1.0.2 module Parser.ProductRule.Internal -- | Two provided symbols besides user defined data. data Symbol a -- | represents the starting symbol. Start :: Symbol a -- | represents the null symbol. Null :: Symbol a -- | represents a terminal symbol. T :: a -> Symbol a -- | represents a non-terminal symbol. NT :: a -> Symbol a -- | represents an undetermined symbol, used internally. UD :: a -> Symbol a type ProductRule t = (Symbol t, [Symbol t]) -- | non-terms -> lhs -> rhs -> product rule rule :: (Ord a) => Symbol a -> [Symbol a] -> ProductRule a -- | non-terms setT :: (Ord a) => Symbol a -> Set a -> Symbol a instance GHC.Classes.Ord a => GHC.Classes.Ord (Parser.ProductRule.Internal.Symbol a) instance GHC.Show.Show a => GHC.Show.Show (Parser.ProductRule.Internal.Symbol a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Parser.ProductRule.Internal.Symbol a) module Parser.ProductRule.Internal.Maker newtype Maker' a x Maker :: (Symbol a, [[Symbol a]]) -> Maker' a x [unMaker] :: Maker' a x -> (Symbol a, [[Symbol a]]) type Maker a = Maker' a () maker :: (Symbol a, [[Symbol a]]) -> Maker a -- | Use ---> iff the left side is the Start symbol and -- the first symbol on the right side is an user-defined symbol. -- -- Only one symbol is allowed on the left hand side. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start ---> A & B ... -- ... --(--->) :: FromMaker m => (Ord a) => Symbol a -> a -> m a () -- | Use --> iff both the left side and the first symbol on the -- right side are user-defined symbols. -- -- | Only one symbol is allowed on the left hand side. -- -- | Use & to concatenate two user-defined symbols. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start ---> ... -- ... -- ; A --> C' -- |/ Null -- ... --(-->) :: FromMaker m => (Ord a) => a -> a -> m a () -- | Use & to concatenate two user-defined symbols. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start >>> Null & C' -- |> ... --(&) :: FromMaker m => Maker a -> a -> m a () -- | Use |> to represent "or" when the left hand side can produce -- two different expressions, and the right side in a user-defined type. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start ---> ... -- ... -- |> C' --(|>) :: FromMaker m => Maker a -> a -> m a () -- | Use |/ iff the right hand side is the Null symbol. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start ---> C' -- |/ Null -- |> ... --(|/) :: FromMaker m => Maker a -> Symbol a -> m a () -- | Use >>> iff the left side is Start and the -- first symbol on the right side is Null. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start >>> Null -- |> C' -- ... --(>>>) :: FromMaker m => Symbol a -> Symbol a -> m a () class FromMaker m fromMaker :: FromMaker m => Maker a -> m a () instance GHC.Base.Functor (Parser.ProductRule.Internal.Maker.Maker' a) instance Parser.ProductRule.Internal.Maker.FromMaker Parser.ProductRule.Internal.Maker.Maker' module Parser.ProductRule.Internal.Manager newtype Manager' a x Manager :: Writer [Maker a] x -> Manager' a x [unManager] :: Manager' a x -> Writer [Maker a] x type Manager a = Manager' a () getMakers :: Manager a -> [Maker a] addMakers :: [Maker a] -> Manager a -> Manager a empty :: Manager a singleton :: Maker a -> Manager a getRules :: (Ord a) => Manager a -> Set a -> [ProductRule a] getNTs :: (Ord a) => Manager a -> Set a -- | Collect the defined syntax and produces a list of production rules. productRules :: (Ord a) => Manager a -> [ProductRule a] instance Control.Monad.Writer.Class.MonadWriter [Parser.ProductRule.Internal.Maker.Maker a] (Parser.ProductRule.Internal.Manager.Manager' a) instance GHC.Base.Monad (Parser.ProductRule.Internal.Manager.Manager' a) instance GHC.Base.Applicative (Parser.ProductRule.Internal.Manager.Manager' a) instance GHC.Base.Functor (Parser.ProductRule.Internal.Manager.Manager' a) instance Parser.ProductRule.Internal.Maker.FromMaker Parser.ProductRule.Internal.Manager.Manager' -- |
-- data MySym = A -- | B -- | C' -- deriving (Eq, Show, Ord) ---- -- where A B are non-terminal symbols, 'C 'D are terminal symbols, we can -- define a production rule table: -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- -- Start ---> A & C' & B -- AC'B concatenation -- |> A -- |> C' -- -- ; A --> B -- You might want to use ";" to clarify the indentation in a `do` block. -- |> A & C' -- |/ Null -- -- ; B --> C' ---- -- This will produce: -- --
-- >>> print $ table -- > -- > [ (Start, [NT A, T C', NT B]) -- > , (Start, [NT A]) -- > , (Start, [T C']) -- > , (NT A, [NT B]) -- > , (NT A, [NT A, T C']) -- > , (NT A, [Null]) -- > , (NT B, [T C']) -- > ] -- > ---- -- where NT represents non-terminal type, and T represents -- terminal type. -- -- This package does not parse the input in any way. It just simplifies -- the way you can define the grammar. module Parser.ProductRule -- | Two provided symbols besides user defined data. data Symbol a -- | represents the starting symbol. Start :: Symbol a -- | represents the null symbol. Null :: Symbol a -- | represents a terminal symbol. T :: a -> Symbol a -- | represents a non-terminal symbol. NT :: a -> Symbol a type ProductRule t = (Symbol t, [Symbol t]) -- | Collect the defined syntax and produces a list of production rules. productRules :: (Ord a) => Manager a -> [ProductRule a] -- | Use ---> iff the left side is the Start symbol and -- the first symbol on the right side is an user-defined symbol. -- -- Only one symbol is allowed on the left hand side. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start ---> A & B ... -- ... --(--->) :: FromMaker m => (Ord a) => Symbol a -> a -> m a () -- | Use --> iff both the left side and the first symbol on the -- right side are user-defined symbols. -- -- | Only one symbol is allowed on the left hand side. -- -- | Use & to concatenate two user-defined symbols. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start ---> ... -- ... -- ; A --> C' -- |/ Null -- ... --(-->) :: FromMaker m => (Ord a) => a -> a -> m a () -- | Use |> to represent "or" when the left hand side can produce -- two different expressions, and the right side in a user-defined type. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start ---> ... -- ... -- |> C' --(|>) :: FromMaker m => Maker a -> a -> m a () -- | Use & to concatenate two user-defined symbols. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start >>> Null & C' -- |> ... --(&) :: FromMaker m => Maker a -> a -> m a () -- | Use |/ iff the right hand side is the Null symbol. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start ---> C' -- |/ Null -- |> ... --(|/) :: FromMaker m => Maker a -> Symbol a -> m a () -- | Use >>> iff the left side is Start and the -- first symbol on the right side is Null. -- --
-- table :: [ProductRule MySym] -- table = productRules $ do -- Start >>> Null -- |> C' -- ... --(>>>) :: FromMaker m => Symbol a -> Symbol a -> m a ()