packages feed

indents 0.3.0 → 0.3.1

raw patch · 2 files changed

+41/−34 lines, 2 filesdep ~basedep ~mtlPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base, mtl

API changes (from Hackage documentation)

- Text.Parsec.Indent: type IndentParserT s u m a = ParsecT s u (StateT SourcePos m) a
+ Text.Parsec.Indent: (<?/>) :: Stream s (State SourcePos) Char => IndentParser s u (a -> b) -> (Optional s u a) -> IndentParser s u b
+ Text.Parsec.Indent: Opt :: a -> (IndentParser s u a) -> Optional s u a
+ Text.Parsec.Indent: data Optional s u a
+ Text.Parsec.Indent: type IndentParser s u a = ParsecT s u (State SourcePos) a
- Text.Parsec.Indent: (<*/>) :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ([a] -> b) -> IndentParserT s u m a -> IndentParserT s u m b
+ Text.Parsec.Indent: (<*/>) :: Stream s (State SourcePos) Char => IndentParser s u ([a] -> b) -> IndentParser s u a -> IndentParser s u b
- Text.Parsec.Indent: (<+/>) :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m (a -> b) -> IndentParserT s u m a -> IndentParserT s u m b
+ Text.Parsec.Indent: (<+/>) :: Stream s (State SourcePos) Char => IndentParser s u (a -> b) -> IndentParser s u a -> IndentParser s u b
- Text.Parsec.Indent: (<-/>) :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m a
+ Text.Parsec.Indent: (<-/>) :: Stream s (State SourcePos) Char => IndentParser s u a -> IndentParser s u b -> IndentParser s u a
- Text.Parsec.Indent: block :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]
+ Text.Parsec.Indent: block :: Stream s (State SourcePos) Char => IndentParser s u a -> IndentParser s u [a]
- Text.Parsec.Indent: checkIndent :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()
+ Text.Parsec.Indent: checkIndent :: Stream s (State SourcePos) Char => IndentParser s u ()
- Text.Parsec.Indent: indentAngles :: (Stream s (StateT SourcePos m) Char, Monad m) => GenTokenParser s u (StateT SourcePos m) -> IndentParserT s u m a -> IndentParserT s u m a
+ Text.Parsec.Indent: indentAngles :: Stream s (State SourcePos) Char => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a
- Text.Parsec.Indent: indentBraces :: (Stream s (StateT SourcePos m) Char, Monad m) => GenTokenParser s u (StateT SourcePos m) -> IndentParserT s u m a -> IndentParserT s u m a
+ Text.Parsec.Indent: indentBraces :: Stream s (State SourcePos) Char => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a
- Text.Parsec.Indent: indentBrackets :: (Stream s (StateT SourcePos m) Char, Monad m) => GenTokenParser s u (StateT SourcePos m) -> IndentParserT s u m a -> IndentParserT s u m a
+ Text.Parsec.Indent: indentBrackets :: Stream s (State SourcePos) Char => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a
- Text.Parsec.Indent: indentParens :: (Stream s (StateT SourcePos m) Char, Monad m) => GenTokenParser s u (StateT SourcePos m) -> IndentParserT s u m a -> IndentParserT s u m a
+ Text.Parsec.Indent: indentParens :: Stream s (State SourcePos) Char => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a
- Text.Parsec.Indent: indented :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()
+ Text.Parsec.Indent: indented :: Stream s (State SourcePos) Char => IndentParser s u ()
- Text.Parsec.Indent: runIndent :: (Monad m) => SourceName -> StateT SourcePos m a -> m a
+ Text.Parsec.Indent: runIndent :: SourceName -> State SourcePos a -> a
- Text.Parsec.Indent: same :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()
+ Text.Parsec.Indent: same :: Stream s (State SourcePos) Char => IndentParser s u ()
- Text.Parsec.Indent: sameOrIndented :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()
+ Text.Parsec.Indent: sameOrIndented :: Stream s (State SourcePos) Char => IndentParser s u ()
- Text.Parsec.Indent: withBlock :: (Stream s (StateT SourcePos m) Char, Monad m) => (a -> [b] -> c) -> IndentParserT s u m a -> IndentParserT s u m x -> IndentParserT s u m b -> IndentParserT s u m c
+ Text.Parsec.Indent: withBlock :: Stream s (State SourcePos) Char => (a -> [b] -> c) -> IndentParser s u a -> IndentParser s u b -> IndentParser s u c
- Text.Parsec.Indent: withBlock' :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m x -> IndentParserT s u m b -> IndentParserT s u m [b]
+ Text.Parsec.Indent: withBlock' :: Stream s (State SourcePos) Char => IndentParser s u a -> IndentParser s u b -> IndentParser s u [b]
- Text.Parsec.Indent: withPos :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m a
+ Text.Parsec.Indent: withPos :: Stream s (State SourcePos) Char => IndentParser s u a -> IndentParser s u a

Files

Text/Parsec/Indent.hs view
@@ -3,7 +3,7 @@     -- $doc          -- * Types-    IndentParserT, runIndent,+    IndentParser, runIndent,     -- * Blocks     withBlock, withBlock', block,     -- * Indentation Checking@@ -12,14 +12,13 @@     indentBrackets, indentAngles, indentBraces, indentParens,     -- * Line Fold Chaining     -- | Any chain using these combinators must used with 'withPos'-    (<+/>), (<-/>), (<*/>)+    (<+/>), (<-/>), (<*/>), (<?/>), Optional(..)     ) where-import Text.Parsec+import Text.Parsec hiding (State) import Text.Parsec.Pos import Text.Parsec.Token import Control.Monad.State import Control.Concatenative-import Debug.Trace  -- $doc -- A module to construct indentation aware parsers. Many programming@@ -48,25 +47,25 @@  -- | Indentation sensitive parser type. Usually @ m @ will --   be @ Identity @ as with any @ ParsecT @-type IndentParserT s u m a = ParsecT s u (StateT SourcePos m) a+type IndentParser s u a = ParsecT s u (State SourcePos) a     --- | @ 'withBlock' f a b p @ parses @ a @ and optionally---   @ b @ followed by an indented block of @ p @---   , combining them with @ f @-withBlock :: (Stream s (StateT SourcePos m) Char, Monad m) => (a -> [b] -> c) ->-    IndentParserT s u m a -> IndentParserT s u m x -> IndentParserT s u m b -> IndentParserT s u m c-withBlock f a b p = withPos $ do+-- | @ 'withBlock' f a p @ parses @ a @+--   followed by an indented block of @ p @+--   combining them with @ f @+withBlock :: (Stream s (State SourcePos) Char) => (a -> [b] -> c) ->+    IndentParser s u a -> IndentParser s u b -> IndentParser s u c+withBlock f a p = withPos $ do     r1 <- a-    r2 <- option [] (b >> indented >> block p)+    r2 <- option [] (indented >> block p)     return (f r1 r2)  -- | Like 'withBlock', but throws away initial parse result-withBlock' :: (Stream s (StateT SourcePos m) Char, Monad m) =>-    IndentParserT s u m a -> IndentParserT s u m x -> IndentParserT s u m b -> IndentParserT s u m [b]+withBlock' :: (Stream s (State SourcePos) Char) =>+    IndentParser s u a -> IndentParser s u b -> IndentParser s u [b] withBlock' = withBlock (flip const)  -- | Parses only when indented past the level of the reference-indented :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()+indented :: (Stream s (State SourcePos) Char) => IndentParser s u () indented = do     pos <- getPosition     s <- get@@ -75,24 +74,24 @@         return ()  -- | Parses only when indented past the level of the reference or on the same line-sameOrIndented :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()+sameOrIndented :: Stream s (State SourcePos) Char => IndentParser s u () sameOrIndented = same <|> indented  -- | Parses only on the same line as the reference-same :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()+same :: (Stream s (State SourcePos) Char) => IndentParser s u () same = do     pos <- getPosition     s <- get     if biAp sourceLine (==) pos s then return () else parserFail "over one line"      -- | Parses a block of lines at the same indentation level-block :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]+block :: (Stream s (State SourcePos) Char) => IndentParser s u a -> IndentParser s u [a] block p = withPos $ do     r <- many1 (checkIndent >> p)     return r  -- | Parses using the current location for indentation reference-withPos :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m a+withPos :: (Stream s (State SourcePos) Char) => IndentParser s u a -> IndentParser s u a withPos x = do     a <- get     p <- getPosition@@ -100,43 +99,51 @@     put a >> return r  -- | Ensures the current indentation level matches that of the reference-checkIndent :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m ()+checkIndent :: (Stream s (State SourcePos) Char) => IndentParser s u () checkIndent = do     s <- get     p <- getPosition     if biAp sourceColumn (==) p s then return () else parserFail "indentation doesn't match"  -- | Run the result of an indentation sensitive parse-runIndent :: Monad m => SourceName -> StateT SourcePos m a -> m a-runIndent s = flip evalStateT (initialPos s)+runIndent :: SourceName -> State SourcePos a -> a+runIndent s = flip evalState (initialPos s)  -- | '<+/>' is to indentation sensitive parsers what 'ap' is to monads-(<+/>) :: (Stream s (StateT SourcePos m) Char, Monad m) =>-    IndentParserT s u m (a -> b) -> IndentParserT s u m a -> IndentParserT s u m b+(<+/>) :: (Stream s (State SourcePos) Char) =>+    IndentParser s u (a -> b) -> IndentParser s u a -> IndentParser s u b a <+/> b = ap a (sameOrIndented >> b)  -- | '<-/>' is like '<+/>', but doesn't apply the function to the parsed value-(<-/>) :: (Stream s (StateT SourcePos m) Char, Monad m) =>-    IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m a+(<-/>) :: (Stream s (State SourcePos) Char) =>+    IndentParser s u a -> IndentParser s u b -> IndentParser s u a a <-/> b = liftM2 const a (sameOrIndented >> b)  -- | Like '<+/>' but applies the second parser many times-(<*/>) :: (Stream s (StateT SourcePos m) Char, Monad m) =>-    IndentParserT s u m ([a] -> b) -> IndentParserT s u m a -> IndentParserT s u m b+(<*/>) :: (Stream s (State SourcePos) Char) =>+    IndentParser s u ([a] -> b) -> IndentParser s u a -> IndentParser s u b a <*/> b = ap a (many (sameOrIndented >> b)) +-- | Datatype used to optional parsing+data Optional s u a = Opt a (IndentParser s u a)++-- | Like '<+/>' but applies the second parser optionally using the 'Optional' datatype+(<?/>) :: (Stream s (State SourcePos) Char) =>+    IndentParser s u (a -> b) -> (Optional s u a) -> IndentParser s u b+(<?/>) a (Opt b c) = ap a (option b (sameOrIndented >> c))+ -- | parses with surrounding brackets-indentBrackets :: (Stream s (StateT SourcePos m) Char, Monad m) => GenTokenParser s u (StateT SourcePos m) -> IndentParserT s u m a -> IndentParserT s u m a+indentBrackets :: (Stream s (State SourcePos) Char) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a indentBrackets lexer p = withPos $ return id <-/> symbol lexer "[" <+/> p <-/> symbol lexer "]"  -- | parses with surrounding angle brackets-indentAngles :: (Stream s (StateT SourcePos m) Char, Monad m) => GenTokenParser s u (StateT SourcePos m) -> IndentParserT s u m a -> IndentParserT s u m a+indentAngles :: (Stream s (State SourcePos) Char) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a indentAngles lexer p = withPos $ return id <-/> symbol lexer "<" <+/> p <-/> symbol lexer ">"  -- | parses with surrounding braces-indentBraces :: (Stream s (StateT SourcePos m) Char, Monad m) => GenTokenParser s u (StateT SourcePos m) -> IndentParserT s u m a -> IndentParserT s u m a+indentBraces :: (Stream s (State SourcePos) Char) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a indentBraces lexer p = withPos $ return id <-/> symbol lexer "{" <+/> p <-/> symbol lexer "}"  -- | parses with surrounding parentheses -indentParens :: (Stream s (StateT SourcePos m) Char, Monad m) => GenTokenParser s u (StateT SourcePos m) -> IndentParserT s u m a -> IndentParserT s u m a+indentParens :: (Stream s (State SourcePos) Char) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a indentParens lexer p = withPos $ return id <-/> symbol lexer "(" <+/> p <-/> symbol lexer ")"
indents.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version:             0.3.0+Version:             0.3.1  -- A short (one-line) description of the package. Synopsis:            indentation sensitive parser-combinators for parsec@@ -51,7 +51,7 @@   Exposed-modules:     Text.Parsec.Indent      -- Packages needed in order to build this package.-  Build-depends: parsec >= 3 && < 4, concatenative < 2, mtl < 2, base < 4.3+  Build-depends: parsec >= 3 && < 4, concatenative < 2, mtl < 3 , base < 4.4      -- Modules not exported by this package.   -- Other-modules: