packages feed

grammar-combinators 0.2.6 → 0.2.7

raw patch · 9 files changed

+47/−44 lines, 9 filesdep +textPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: text

API changes (from Hackage documentation)

- Text.GrammarCombinators.Parser.UUParse: instance (ConcreteToken t ~ ct, Token t, Show ct, IsLocationUpdatedBy loc ct) => TokenProductionRule (WrapP t loc ct) t
- Text.GrammarCombinators.Utils.CalcFirst: instance Token t => Show (FirstSet t)
+ Text.GrammarCombinators.Parser.UUParse: instance (Token t, Show ct, ConcreteToken t ~ ct, IsLocationUpdatedBy loc ct) => TokenProductionRule (WrapP t loc ct) t
+ Text.GrammarCombinators.Utils.CalcFirst: instance Show t => Show (FirstSet t)
- Text.GrammarCombinators.Base.Domain: class EqFam phi
+ Text.GrammarCombinators.Base.Domain: class EqFam phi where eqIdx idx1 = overrideIdxK (const False) idx1 True
- Text.GrammarCombinators.Base.Domain: class MemoFam phi :: (* -> *) where { data family Memo phi :: (* -> *) -> *; }
+ Text.GrammarCombinators.Base.Domain: class MemoFam (phi :: * -> *) where data family Memo phi :: (* -> *) -> *
- Text.GrammarCombinators.Base.Domain: data IxMapBase m :: (* -> *)
+ Text.GrammarCombinators.Base.Domain: data IxMapBase (m :: * -> *)
- Text.GrammarCombinators.Base.Domain: data IxMapSeq l1 :: * l2 :: (* -> *)
+ Text.GrammarCombinators.Base.Domain: data IxMapSeq (l1 :: *) (l2 :: * -> *)
- Text.GrammarCombinators.Base.Domain: data SubVal supIxT :: (* -> *) v ix
+ Text.GrammarCombinators.Base.Domain: data SubVal (supIxT :: * -> *) v ix
- Text.GrammarCombinators.Base.Grammar: type GGrammar rt phi t r rr = forall ix. phi ix -> rt phi r t (rr ix)
+ Text.GrammarCombinators.Base.Grammar: type GGrammar rt phi t (r :: * -> *) (rr :: * -> *) = forall ix. phi ix -> rt phi r t (rr ix)
- Text.GrammarCombinators.Base.MultiRec: data SubPF phi :: (* -> *) phi' :: (* -> *) unusedPhi' supIxT r ix
+ Text.GrammarCombinators.Base.MultiRec: data SubPF (phi :: * -> *) (phi' :: * -> *) unusedPhi' supIxT r ix
- Text.GrammarCombinators.Base.ProductionRule: class BiasedProductionRule p
+ Text.GrammarCombinators.Base.ProductionRule: class BiasedProductionRule p where >||| = flip (<|||) <||| = flip (>|||)
- Text.GrammarCombinators.Base.ProductionRule: class ProductionRule p => LiftableProductionRule p
+ Text.GrammarCombinators.Base.ProductionRule: class ProductionRule p => LiftableProductionRule p where optionally r = epsilonL Just [| Just |] >>> r ||| epsilonL Nothing [| Nothing |]
- Text.GrammarCombinators.Base.ProductionRule: class (ProductionRule p, LiftableProductionRule p, RecProductionRule p phi r) => LoopProductionRule p phi r | p -> phi, p -> r
+ Text.GrammarCombinators.Base.ProductionRule: class (ProductionRule p, LiftableProductionRule p, RecProductionRule p phi r) => LoopProductionRule p phi r | p -> phi, p -> r where manyRef idx = epsilonL [] [| [] |] ||| many1Ref idx many1Ref idx = ((:), [| (:) |]) $|>> ref idx >>> manyRef idx
- Text.GrammarCombinators.Base.Token: class (Show (ConcreteToken t), Eq (ConcreteToken t), Lift (ConcreteToken t), Eq t, Show t, Ord t, Lift t, Enumerable t) => Token t where { type family ConcreteToken t; }
+ Text.GrammarCombinators.Base.Token: class (Show (ConcreteToken t), Eq (ConcreteToken t), Lift (ConcreteToken t), Eq t, Show t, Ord t, Lift t, Enumerable t) => Token t where type family ConcreteToken t
- Text.GrammarCombinators.Transform.PenalizeErrors: newtype PBEHProductionRule p phi :: (* -> *) unusedR :: (* -> *) r :: (* -> *) t v
+ Text.GrammarCombinators.Transform.PenalizeErrors: newtype PBEHProductionRule p (phi :: * -> *) (unusedR :: * -> *) (r :: * -> *) t v
- Text.GrammarCombinators.Utils.CalcFirst: data FSCalculator phi r :: (* -> *) t rr v
+ Text.GrammarCombinators.Utils.CalcFirst: data FSCalculator phi (r :: * -> *) t rr v
- Text.GrammarCombinators.Utils.CalcFirst: data Token t => FirstSet t
+ Text.GrammarCombinators.Utils.CalcFirst: data FirstSet t
- Text.GrammarCombinators.Utils.EnumerateGrammar: IPP :: (EnumerateParserInternalGrammar phi t -> Int -> [[ConcreteToken t]]) -> EnumerateProductionRule phi ixT r t v
+ Text.GrammarCombinators.Utils.EnumerateGrammar: IPP :: (EnumerateParserInternalGrammar phi t -> Int -> [[ConcreteToken t]]) -> EnumerateProductionRule phi ixT t v
- Text.GrammarCombinators.Utils.EnumerateGrammar: newtype EnumerateProductionRule phi ixT r t v
+ Text.GrammarCombinators.Utils.EnumerateGrammar: newtype EnumerateProductionRule phi ixT (r :: * -> *) t v
- Text.GrammarCombinators.Utils.EnumerateGrammar: printIPP :: EnumerateProductionRule phi ixT r t v -> EnumerateParserInternalGrammar phi t -> Int -> [[ConcreteToken t]]
+ Text.GrammarCombinators.Utils.EnumerateGrammar: printIPP :: EnumerateProductionRule phi ixT t v -> EnumerateParserInternalGrammar phi t -> Int -> [[ConcreteToken t]]
- Text.GrammarCombinators.Utils.EnumerateGrammar: type EnumerateGrammar phi ixT r :: (* -> *) t rr = forall ix. phi ix -> EnumerateProductionRule phi ixT r t (rr ix)
+ Text.GrammarCombinators.Utils.EnumerateGrammar: type EnumerateGrammar phi ixT (r :: * -> *) t rr = forall ix. phi ix -> EnumerateProductionRule phi ixT r t (rr ix)
- Text.GrammarCombinators.Utils.ToGraph: showGraph :: DotRepr dg n => dg n -> IO ()
+ Text.GrammarCombinators.Utils.ToGraph: showGraph :: PrintDotRepr dg n => dg n -> IO ()
- Text.GrammarCombinators.Utils.UnfoldDepthFirst: class ProductionRule p => SimpleRecProductionRule p phi r rr | p -> phi, p -> r, p -> rr
+ Text.GrammarCombinators.Utils.UnfoldDepthFirst: class ProductionRule p => SimpleRecProductionRule p phi r rr | p -> phi, p -> r, p -> rr where cutRecursion _ = die
- Text.GrammarCombinators.Utils.UnfoldDepthFirst: newtype UnfoldDepthFirstRule p phi :: (* -> *) r :: (* -> *) t rr :: (* -> *) v
+ Text.GrammarCombinators.Utils.UnfoldDepthFirst: newtype UnfoldDepthFirstRule p (phi :: * -> *) (r :: * -> *) t (rr :: * -> *) v
- Text.GrammarCombinators.Utils.UnfoldDepthFirst: type UDFGrammar p phi r t rr = forall ix. phi ix -> p (rr ix)
+ Text.GrammarCombinators.Utils.UnfoldDepthFirst: type UDFGrammar p phi (r :: * -> *) t rr = forall ix. phi ix -> p (rr ix)

Files

Text/GrammarCombinators/Base/Grammar.hs view
@@ -19,6 +19,7 @@ -} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE KindSignatures #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -27,15 +28,15 @@ import Text.GrammarCombinators.Base.ProductionRule import Text.GrammarCombinators.Base.MultiRec -type RegularRule phi r t v =+type RegularRule (phi :: * -> *) (r :: * -> *) t v =   forall p. (ProductionRule p, EpsProductionRule p, TokenProductionRule p t) =>   p v -type PenaltyRegularRule phi r t v =+type PenaltyRegularRule (phi :: * -> *) (r :: * -> *) t v =   forall p. (ProductionRule p, EpsProductionRule p, TokenProductionRule p t, PenaltyProductionRule p) =>   p v -type BiasedRegularRule phi r t v =+type BiasedRegularRule (phi :: * -> *) (r :: * -> *) t v =   forall p. (ProductionRule p, EpsProductionRule p, TokenProductionRule p t, BiasedProductionRule p) =>   p v @@ -83,7 +84,7 @@   forall p. (ProductionRule p, LiftableProductionRule p, RecProductionRule p phi r, TokenProductionRule p t, LoopProductionRule p phi r) =>   p v -type GGrammar rt phi t r rr = +type GGrammar rt phi t (r :: * -> *) (rr :: * -> *) =    forall ix. phi ix -> rt phi r t (rr ix) type AGrammar rt phi t = forall r. GGrammar rt phi t r (PF phi r) type PGrammar rt phi t r = GGrammar rt phi t r r
Text/GrammarCombinators/Parser/Packrat.hs view
@@ -66,7 +66,7 @@   fromMemo (PRMemo (v, _, _)) (PackratDomainPrimToken) = v   fromMemo (PRMemo (_, v, _)) (PackratDomainEndOfInput) = v -data PackratValue phi t r ix where+data PackratValue (phi :: * -> *) t r ix where   PRPrimTokenValue :: ConcreteToken t -> PackratValue phi t r PRPrimTokenIx   PREndOfInputValue :: PackratValue phi t r PREndOfInputIx   PRBaseValue :: r ix -> PackratValue phi t r (PRBaseIx ix)
Text/GrammarCombinators/Utils/CalcFirst.hs view
@@ -34,7 +34,7 @@  import Text.GrammarCombinators.Base -data (Token t) => FirstSet t = +data FirstSet t =    FS {     firstSet :: Set t,     canBeEmpty :: Bool, 
Text/GrammarCombinators/Utils/EnumerateGrammar.hs view
@@ -33,7 +33,7 @@  type EnumerateParserInternalGrammar phi t = forall ix . phi ix -> Int -> [[ConcreteToken t]] -newtype EnumerateProductionRule phi ixT r t v = IPP {+newtype EnumerateProductionRule phi ixT (r :: * -> *) t v = IPP {   printIPP :: EnumerateParserInternalGrammar phi t -> Int -> [[ConcreteToken t]]   } 
Text/GrammarCombinators/Utils/IsReachable.hs view
@@ -37,35 +37,33 @@ import Control.Monad.State  newtype SeenGram phi = MkSG { seenIdx :: forall ix. phi ix -> Bool }-newtype Folder phi n = MkFF { foldIdxs :: (forall ix. phi ix -> n -> n) -> n -> n }-newtype FoldReachableIntRule phi (r :: * -> *) t (rr :: * -> *) n v = MkFRIR {-  foldRule :: State (SeenGram phi) (Folder phi n)-  }-combineFolders :: Folder phi n -> Folder phi n -> Folder phi n-combineFolders a b = MkFF $ \f n -> foldIdxs a f $ foldIdxs b f n-foldDeadEnd :: FoldReachableIntRule phi r t rr n v -foldDeadEnd = MkFRIR $ return $ MkFF $ \_ n -> n-foldVia :: FoldReachableIntRule phi r t rr n v -> FoldReachableIntRule phi r t rr n v' -> FoldReachableIntRule phi r t rr n v''  -foldVia ra rb = MkFRIR $ do fa <- foldRule ra-                            fb <- foldRule rb-                            return $ combineFolders fa fb setSeen :: (EqFam phi) => phi ix -> SeenGram phi -> SeenGram phi setSeen idx s = MkSG $ overrideIdxK (seenIdx s) idx True+nothingSeen :: SeenGram phi+nothingSeen = MkSG $ \_ -> False++type Folder phi n = forall ix. phi ix -> n -> n++newtype FoldReachableIntRule phi (r :: * -> *) t (rr :: * -> *) n v = MkFRIR {+  foldRule :: Folder phi n -> n -> State (SeenGram phi) n+  } putSeen :: (EqFam phi) => phi ix -> State (SeenGram phi) () putSeen idx = modify $ setSeen idx-noFold :: Folder phi n-noFold = MkFF $ const id-foldIdx :: phi ix -> Folder phi n-foldIdx idx = MkFF $ \f n -> f idx n++foldDeadEnd :: FoldReachableIntRule phi r t rr n v +foldDeadEnd = MkFRIR $ \_ n -> return n+foldVia :: FoldReachableIntRule phi r t rr n v -> FoldReachableIntRule phi r t rr n v' -> FoldReachableIntRule phi r t rr n v''  +foldVia ra rb = MkFRIR $ \f n -> do n' <- foldRule ra f n+                                    foldRule rb f n' foldRef :: (EqFam phi) =>            phi ix -> FoldReachableIntRule phi r t rr n (rr ix) ->             FoldReachableIntRule phi r t rr n v-foldRef idx r = MkFRIR $ do s <- get-                            if seenIdx s idx-                              then return noFold-                              else do putSeen idx-                                      frec <- foldRule r -                                      return $ combineFolders frec $ foldIdx idx+foldRef idx r = MkFRIR $ \f n -> do sg <- get+                                    if seenIdx sg idx+                                      then return n+                                      else do putSeen idx+                                              let n' = f idx n+                                              foldRule r f n'  instance ProductionRule (FoldReachableIntRule phi r t rr n) where   ra >>> rb = foldVia ra rb@@ -99,9 +97,6 @@   manyRef' = foldRef    many1Ref' = foldRef  -nothingSeen :: SeenGram phi-nothingSeen = MkSG $ \_ -> False- -- | Fold a given function over all non-terminals that are reachable  -- from a given non-terminal. This function is limited to proper -- reachable rules (see 'isReachableProper' for what that means).@@ -109,8 +104,8 @@                        GAnyExtendedContextFreeGrammar phi t r rr ->                        phi ix ->                        (forall ix'. phi ix' -> n -> n) -> n -> n-foldReachableProper grammar idx =-  foldIdxs $ evalState (foldRule (unfoldDepthFirstProper grammar idx)) nothingSeen+foldReachableProper grammar idx f n =+  evalState (foldRule (unfoldDepthFirstProper grammar idx) f n) nothingSeen  -- | Fold a given function over all non-terminals that are reachable  -- from a given non-terminal. This function will at least fold over the@@ -119,8 +114,8 @@                  GAnyExtendedContextFreeGrammar phi t r rr ->                  phi ix ->                  (forall ix'. phi ix' -> n -> n) -> n -> n-foldReachable grammar idx =-  foldIdxs $ evalState (foldRule (unfoldDepthFirst grammar idx)) nothingSeen+foldReachable grammar idx f n =+  evalState (foldRule (unfoldDepthFirst grammar idx) f n) nothingSeen  isReachable' :: forall phi r t rr ix ix'. (Domain phi) =>                 (forall n. 
Text/GrammarCombinators/Utils/ToGraph.hs view
@@ -36,6 +36,8 @@  import Text.GrammarCombinators.Utils.IsReachable +import Data.String (fromString)+ import Data.Graph.Inductive.Graph  import Control.Monad.State@@ -132,19 +134,20 @@     (contexts, (_,nsn)) = flip runState (depth, sn) $ execWriterT $ processNTDef idx   in (nsn, reverse contexts) -graphvizParams :: GraphvizParams String String () String+graphvizParams :: GraphvizParams Node String String () String graphvizParams = Params {   isDirected = True,    globalAttributes = [],    clusterBy = N, -  clusterID = const Nothing,+  clusterID = \_ -> undefined,+  isDotCluster = \_ -> undefined,   fmtCluster = const [],-  fmtNode = \(_,n) -> [Label $ StrLabel n],+  fmtNode = \(_,n) -> [toLabel n],   fmtEdge = \(_,_,_) -> []    }  graphToGraphviz :: Gr String String -> DotGraph Node-graphToGraphviz gr = setID (Str "Grammar") $ graphToDot graphvizParams (gr :: Gr String String)+graphToGraphviz gr = setID (Str $ fromString "Grammar") $ graphToDot graphvizParams (gr :: Gr String String)  grammarToContexts :: forall phi t r rr . (Token t, Domain phi) =>                      (forall b. (forall ix. phi ix -> b -> b) -> b -> b) ->@@ -171,5 +174,5 @@                   gr String String reachableGrammarToGraph depth gram idx = grammarToGraph (foldReachable gram idx) depth gram -showGraph :: (DotRepr dg n) => dg n -> IO ()+showGraph :: (PrintDotRepr dg n) => dg n -> IO () showGraph gr = runGraphvizCanvas' gr Xlib >> return ()
Text/GrammarCombinators/Utils/UnfoldDepthFirst.hs view
@@ -44,7 +44,7 @@   foldReachableFromRule :: UDFGrammar p phi r t rr -> p v   } -type UDFGrammar p phi r t rr =+type UDFGrammar p phi (r :: * -> *) t rr =   forall ix. phi ix -> p (rr ix)  instance (ProductionRule p) => ProductionRule (UnfoldDepthFirstRule p phi r t rr) where
changelog view
@@ -1,5 +1,8 @@ -*-change-log-*- +0.2.7+	Fix compilation with GHC 7.4 and recent versions of various+	libraries. 0.2.6 	Fix the previous fix with GHC 7. 0.2.5 Fix compatibility with non-backwards compatible UUParse 2.7.1.
grammar-combinators.cabal view
@@ -1,5 +1,5 @@ Name:                grammar-combinators-Version:             0.2.6+Version:             0.2.7 Description:     The grammar-combinators library is a novel parsing library using     an explicit representation of recursion to provide various novel@@ -28,7 +28,8 @@                      MaybeT >= 0.1.2,                      uu-parsinglib >= 2.5.1,                      graphviz >= 2999.10,-                     fgl >= 5.4.2.2+                     fgl >= 5.4.2.2,+                     text >= 0.11   Exposed-modules:   Text.GrammarCombinators.Base.Domain                      Text.GrammarCombinators.Base.Grammar                      Text.GrammarCombinators.Base