Hello community, here is the log from the commit of package ghc-indents for openSUSE:Factory checked in at 2017-03-12 20:03:14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-indents (Old) and /work/SRC/openSUSE:Factory/.ghc-indents.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-indents" Sun Mar 12 20:03:14 2017 rev:2 rq:477657 version:0.4.0.0 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-indents/ghc-indents.changes 2017-02-28 23:48:03.418551272 +0100 +++ /work/SRC/openSUSE:Factory/.ghc-indents.new/ghc-indents.changes 2017-03-12 20:03:15.192097368 +0100 @@ -1,0 +2,5 @@ +Sun Feb 12 14:17:24 UTC 2017 - psim...@suse.com + +- Update to version 0.4.0.0 with cabal2obs. + +------------------------------------------------------------------- Old: ---- indents-0.3.3.tar.gz New: ---- indents-0.4.0.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-indents.spec ++++++ --- /var/tmp/diff_new_pack.6DC3ku/_old 2017-03-12 20:03:15.668030023 +0100 +++ /var/tmp/diff_new_pack.6DC3ku/_new 2017-03-12 20:03:15.672029457 +0100 @@ -1,7 +1,7 @@ # # spec file for package ghc-indents # -# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,22 +17,24 @@ %global pkg_name indents +%bcond_with tests Name: ghc-%{pkg_name} -Version: 0.3.3 +Version: 0.4.0.0 Release: 0 Summary: Indentation sensitive parser-combinators for parsec License: BSD-3-Clause -Group: System/Libraries +Group: Development/Languages/Other Url: https://hackage.haskell.org/package/%{pkg_name} Source0: https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz BuildRequires: ghc-Cabal-devel -# Begin cabal-rpm deps: -BuildRequires: ghc-concatenative-devel BuildRequires: ghc-mtl-devel BuildRequires: ghc-parsec-devel BuildRequires: ghc-rpm-macros BuildRoot: %{_tmppath}/%{name}-%{version}-build -# End cabal-rpm deps +%if %{with tests} +BuildRequires: ghc-tasty-devel +BuildRequires: ghc-tasty-hunit-devel +%endif %description This library provides functions for use in parsing indentation sensitive @@ -53,14 +55,14 @@ %prep %setup -q -n %{pkg_name}-%{version} - %build %ghc_lib_build - %install %ghc_lib_install +%check +%cabal_test %post devel %ghc_pkg_recache @@ -74,5 +76,6 @@ %files devel -f %{name}-devel.files %defattr(-,root,root,-) +%doc CHANGELOG.md %changelog ++++++ indents-0.3.3.tar.gz -> indents-0.4.0.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/indents-0.3.3/CHANGELOG.md new/indents-0.4.0.0/CHANGELOG.md --- old/indents-0.3.3/CHANGELOG.md 1970-01-01 01:00:00.000000000 +0100 +++ new/indents-0.4.0.0/CHANGELOG.md 2016-12-22 17:02:32.000000000 +0100 @@ -0,0 +1,11 @@ +Changelog +========= + +- 0.4.0.0 (2016-12-22) + * Improved error messages + * Added a simple test suite + * Use `ReaderT` stack instead of `State` + * Add `IndentParserT` in addition to `IndentParser` + * Remove dependency on `concatenative` + * Add `topLevel`, `notTopLevel` functions + * Add `runIndentParserT`, `runIndentParser` convenience functions diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/indents-0.3.3/Text/Parsec/Indent.hs new/indents-0.4.0.0/Text/Parsec/Indent.hs --- old/indents-0.3.3/Text/Parsec/Indent.hs 2012-05-19 00:00:31.000000000 +0200 +++ new/indents-0.4.0.0/Text/Parsec/Indent.hs 1970-01-01 01:00:00.000000000 +0100 @@ -1,149 +0,0 @@ -{-# LANGUAGE FlexibleContexts #-} -module Text.Parsec.Indent ( - -- $doc - - -- * Types - IndentParser, runIndent, - -- * Blocks - withBlock, withBlock', block, - -- * Indentation Checking - indented, same, sameOrIndented, checkIndent, withPos, - -- * Paired characters - indentBrackets, indentAngles, indentBraces, indentParens, - -- * Line Fold Chaining - -- | Any chain using these combinators must used with 'withPos' - (<+/>), (<-/>), (<*/>), (<?/>), Optional(..) - ) where -import Text.Parsec hiding (State) -import Text.Parsec.Pos -import Text.Parsec.Token -import Control.Monad.State -import Control.Concatenative - --- $doc --- A module to construct indentation aware parsers. Many programming --- language have indentation based syntax rules e.g. python and Haskell. --- This module exports combinators to create such parsers. --- --- The input source can be thought of as a list of tokens. Abstractly --- each token occurs at a line and a column and has a width. The column --- number of a token measures is indentation. If t1 and t2 are two tokens --- then we say that indentation of t1 is more than t2 if the column --- number of occurrence of t1 is greater than that of t2. --- --- Currently this module supports two kind of indentation based syntactic --- structures which we now describe: --- --- [Block] A block of indentation /c/ is a sequence of tokens with --- indentation at least /c/. Examples for a block is a where clause of --- Haskell with no explicit braces. --- --- [Line fold] A line fold starting at line /l/ and indentation /c/ is a --- sequence of tokens that start at line /l/ and possibly continue to --- subsequent lines as long as the indentation is greater than /c/. Such --- a sequence of lines need to be /folded/ to a single line. An example --- is MIME headers. Line folding based binding separation is used in --- Haskell as well. - --- | Indentation sensitive parser type. Usually @ m @ will --- be @ Identity @ as with any @ ParsecT @ -type IndentParser s u a = ParsecT s u (State SourcePos) a - --- | @ 'withBlock' f a p @ parses @ a @ --- followed by an indented block of @ p @ --- combining them with @ f @ -withBlock :: (Stream s (State SourcePos) z) => (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 [] (indented >> block p) - return (f r1 r2) - --- | Like 'withBlock', but throws away initial parse result -withBlock' :: (Stream s (State SourcePos) z) => - 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 (State SourcePos) z) => IndentParser s u () -indented = do - pos <- getPosition - s <- get - if biAp sourceColumn (<=) pos s then parserFail "not indented" else do - put $ setSourceLine s (sourceLine pos) - return () - --- | Parses only when indented past the level of the reference or on the same line -sameOrIndented :: Stream s (State SourcePos) z => IndentParser s u () -sameOrIndented = same <|> indented - --- | Parses only on the same line as the reference -same :: (Stream s (State SourcePos) z) => 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 (State SourcePos) z) => 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 (State SourcePos) z) => IndentParser s u a -> IndentParser s u a -withPos x = do - a <- get - p <- getPosition - r <- put p >> x - put a >> return r - --- | Ensures the current indentation level matches that of the reference -checkIndent :: (Stream s (State SourcePos) z) => 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 :: SourceName -> State SourcePos a -> a -runIndent s = flip evalState (initialPos s) - --- | '<+/>' is to indentation sensitive parsers what 'ap' is to monads -(<+/>) :: (Stream s (State SourcePos) z) => - 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 (State SourcePos) z) => - 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 (State SourcePos) z) => - 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) z) => - 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 (State SourcePos) z) => 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 (State SourcePos) z) => 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 (State SourcePos) z) => 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 (State SourcePos) z) => GenTokenParser s u (State SourcePos) -> IndentParser s u a -> IndentParser s u a -indentParens lexer p = withPos $ return id <-/> symbol lexer "(" <+/> p <-/> symbol lexer ")" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/indents-0.3.3/indents.cabal new/indents-0.4.0.0/indents.cabal --- old/indents-0.3.3/indents.cabal 2012-05-19 00:00:31.000000000 +0200 +++ new/indents-0.4.0.0/indents.cabal 2016-12-22 17:02:32.000000000 +0100 @@ -1,61 +1,53 @@ --- indents.cabal auto-generated by cabal init. For additional options, --- see --- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr. --- The name of the package. Name: indents - --- 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.3 - --- A short (one-line) description of the package. +Version: 0.4.0.0 Synopsis: indentation sensitive parser-combinators for parsec - --- A longer description of the package. -Description: This library provides functions for use in parsing indentation sensitive contexts. It parses blocks of lines all indented to the same level as well as lines continued at an indented level below. - --- URL for the project homepage or repository. -Homepage: http://patch-tag.com/r/salazar/indents - --- The license under which the package is released. +Description: This library provides functions for use in parsing indentation sensitive contexts. It parses blocks of lines all indented to the same level as well as lines continued at an indented level below. +Homepage: http://github.com/jaspervdj/indents License: BSD3 - --- The file containing the license text. License-file: LICENSE - --- The package author(s). -Author: Sam Anklesaria - --- An email address to which users can send suggestions, bug reports, --- and patches. -Maintainer: am...@amsay.net - --- A copyright notice. --- Copyright: - +Author: Sam Anklesaria, Jasper Van der Jeugt +Maintainer: jasper...@gmail.com Category: Text, Parsing - Build-type: Simple +Cabal-version: >=1.8 --- Extra files to be distributed with the package, such as examples or --- a README. --- Extra-source-files: - --- Constraint on the version of Cabal needed to build this package. -Cabal-version: >=1.2 +Extra-source-files: + CHANGELOG.md +Source-repository head + Type: git + Location: g...@github.com:jaspervdj/indents.git Library - -- Modules exported by the library. - Exposed-modules: Text.Parsec.Indent - - -- Packages needed in order to build this package. - Build-depends: parsec >= 3 && < 4, concatenative < 2, mtl < 3 , base < 5 - - -- Modules not exported by this package. - -- Other-modules: - - -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source. - -- Build-tools: - + Hs-source-dirs: src + + If impl(ghc >= 8.0) + Ghc-options: -Wall -fno-warn-redundant-constraints + Else + Ghc-options: -Wall + + Exposed-modules: + Text.Parsec.Indent + + Build-depends: + base >= 4 && < 5, + parsec >= 3 && < 3.2, + mtl >= 1 && < 2.3 + +Test-suite indents-tests + Ghc-options: -Wall + Hs-source-dirs: tests + Main-is: Main.hs + Type: exitcode-stdio-1.0 + + Other-modules: + Text.Parsec.Indent.Tests + + Build-depends: + indents, + tasty >= 0.11 && < 0.12, + tasty-hunit >= 0.9 && < 0.10, + -- Copy-pasted from 'Library' dependencies. + base >= 4 && < 5, + parsec >= 3 && < 3.2, + mtl >= 1 && < 2.3 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/indents-0.3.3/src/Text/Parsec/Indent.hs new/indents-0.4.0.0/src/Text/Parsec/Indent.hs --- old/indents-0.3.3/src/Text/Parsec/Indent.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/indents-0.4.0.0/src/Text/Parsec/Indent.hs 2016-12-22 17:02:32.000000000 +0100 @@ -0,0 +1,277 @@ +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE MultiParamTypeClasses #-} +module Text.Parsec.Indent ( + -- $doc + + -- * Types + IndentT, IndentParserT, IndentParser, runIndent, + runIndentParserT, runIndentParser, + -- * Blocks + withBlock, withBlock', block, + -- * Indentation Checking + indented, same, sameOrIndented, checkIndent, + topLevel, notTopLevel, + withPos, + -- * Paired characters + indentBrackets, indentAngles, indentBraces, indentParens, + -- * Line Fold Chaining + -- | Any chain using these combinators must used with 'withPos' + (<+/>), (<-/>), (<*/>), (<?/>), Optional(..) + ) where + +import Control.Monad (ap, liftM2, unless, when) +import Control.Monad.Identity (Identity, runIdentity) +import Control.Monad.Reader (ReaderT, ask, local, runReaderT) +import Text.Parsec +import Text.Parsec.Token + +-- $doc +-- A module to construct indentation aware parsers. Many programming +-- language have indentation based syntax rules e.g. python and Haskell. +-- This module exports combinators to create such parsers. +-- +-- The input source can be thought of as a list of tokens. Abstractly +-- each token occurs at a line and a column and has a width. The column +-- number of a token measures is indentation. If t1 and t2 are two tokens +-- then we say that indentation of t1 is more than t2 if the column +-- number of occurrence of t1 is greater than that of t2. +-- +-- Currently this module supports two kind of indentation based syntactic +-- structures which we now describe: +-- +-- [Block] A block of indentation /c/ is a sequence of tokens with +-- indentation at least /c/. Examples for a block is a where clause of +-- Haskell with no explicit braces. +-- +-- [Line fold] A line fold starting at line /l/ and indentation /c/ is a +-- sequence of tokens that start at line /l/ and possibly continue to +-- subsequent lines as long as the indentation is greater than /c/. Such +-- a sequence of lines need to be /folded/ to a single line. An example +-- is MIME headers. Line folding based binding separation is used in +-- Haskell as well. + +-- | We use our own 'Position' type that doesn't require a 'SourceName'. +data Pos = Pos + { pLine :: !Int + , pColumn :: !Int + } deriving (Show) + +showIndent :: Pos -> String +showIndent pos = case pColumn pos of + 1 -> "top-level indentation" + c -> show (c - 1) ++ "-column indentation" + +showLine :: Pos -> String +showLine = show . pLine + +getCurrentPos :: Monad m => IndentParserT s u m Pos +getCurrentPos = do + pos <- getPosition + return $! Pos {pLine = sourceLine pos, pColumn = sourceColumn pos} + +getReferencePos :: Monad m => IndentParserT s u m Pos +getReferencePos = ask + +-- | Indentation transformer. +type IndentT m = ReaderT Pos m + +-- | Indentation sensitive parser type. Usually @m@ will be 'Identity' as with +-- any 'ParsecT'. In that case you can use the simpler 'IndentParser' type. +type IndentParserT s u m a = ParsecT s u (IndentT m) a + +-- | A simplified 'IndentParserT'. +type IndentParser s u a = IndentParserT s u Identity a + +-- | @ 'withBlock' f a p @ parses @ a @ +-- followed by an indented block of @ p @ +-- combining them with @ f @ +withBlock + :: (Monad m, Stream s (IndentT m) z) + => (a -> [b] -> c) + -> IndentParserT s u m a + -> IndentParserT s u m b + -> IndentParserT s u m c +withBlock f a p = withPos $ do + r1 <- a + r2 <- option [] (indented >> block p) + return (f r1 r2) + +-- | Like 'withBlock', but throws away initial parse result +withBlock' + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m a + -> IndentParserT s u m b + -> IndentParserT s u m [b] +withBlock' = withBlock (flip const) + +-- | Parses only when indented past the level of the reference +indented + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m () +indented = do + pos <- getCurrentPos + ref <- getReferencePos + when (pColumn pos <= pColumn ref) $ unexpected (showIndent pos) + +-- | Parses only when indented past the level of the reference or on the same line +sameOrIndented + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m () +sameOrIndented = do + -- This is equal to 'same <|> indented' but gives a cleaner error message. + pos <- getCurrentPos + ref <- getReferencePos + when (pColumn pos <= pColumn ref && pLine pos /= pLine ref) $ + unexpected (showIndent pos) + +-- | Parses only on the same line as the reference +same + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m () +same = do + pos <- getCurrentPos + ref <- getReferencePos + when (pLine pos /= pLine ref) $ unexpected "line break" + +-- | Parses a block of lines at the same indentation level +block + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m a + -> IndentParserT s u m [a] +block p = withPos $ do + r <- many1 (checkIndent >> p) + return r + +-- | Parses using the current location for indentation reference +withPos + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m a + -> IndentParserT s u m a +withPos x = do + p <- getCurrentPos + local (const p) x + +-- | Ensures the current indentation level matches that of the reference +checkIndent + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m () +checkIndent = do + ref <- getReferencePos + pos <- getCurrentPos + when (pColumn pos /= pColumn ref) $ + (<?> showIndent ref ++ " (started at line " ++ showLine ref ++ ")") + (unexpected $ showIndent pos) + +-- | Ensures that there is no indentation. +topLevel + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m () +topLevel = do + pos <- getCurrentPos + unless (pColumn pos == 1) $ unexpected "indentation" + +-- | Ensures that there is at least some indentation. +notTopLevel + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m () +notTopLevel = do + pos <- getCurrentPos + when (pColumn pos == 1) $ unexpected "top-level" + +-- | Run the result of an indentation sensitive parse +runIndentT :: Monad m => IndentT m a -> m a +runIndentT i = runReaderT i (Pos 1 1) + +-- | Simplified version of 'runIndentT'. +runIndent :: IndentT Identity a -> a +runIndent = runIdentity . runIndentT + +-- | This is a convenience function which wraps 'runIndentT' and 'runParserT'. +runIndentParserT + :: (Monad m, Stream s (IndentT m) t) + => IndentParserT s u m a -- ^ Parser to run + -> u -- ^ User state + -> SourceName -- ^ Source name + -> s -- ^ Input for the parser + -> m (Either ParseError a) -- ^ Result +runIndentParserT parser u source txt = + runIndentT (runParserT parser u source txt) + +-- | This is another convenience function. Use this instead of +-- 'runIndentParserT' if 'm' is 'Identity'. +runIndentParser + :: Stream s (IndentT Identity) t + => IndentParser s u a -- ^ Parser to run + -> u -- ^ User state + -> SourceName -- ^ Source name + -> s -- ^ Input for the parser + -> Either ParseError a -- ^ Result +runIndentParser parser u source txt = + runIdentity (runIndentParserT parser u source txt) + +-- | '<+/>' is to indentation sensitive parsers what 'ap' is to monads +(<+/>) + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m (a -> b) + -> IndentParserT s u m a + -> IndentParserT s u m b +a <+/> b = ap a (sameOrIndented >> b) + +-- | '<-/>' is like '<+/>', but doesn't apply the function to the parsed value +(<-/>) + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m a + -> IndentParserT s u m b + -> IndentParserT s u m a +a <-/> b = liftM2 const a (sameOrIndented >> b) + +-- | Like '<+/>' but applies the second parser many times +(<*/>) + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m ([a] -> b) + -> IndentParserT s u m a + -> IndentParserT s u m b +a <*/> b = ap a (many (sameOrIndented >> b)) + +-- | Datatype used to optional parsing +data Optional s u m a = Opt a (IndentParserT s u m a) + +-- | Like '<+/>' but applies the second parser optionally using the 'Optional' datatype +(<?/>) + :: (Monad m, Stream s (IndentT m) z) + => IndentParserT s u m (a -> b) + -> (Optional s u m a) + -> IndentParserT s u m b +(<?/>) a (Opt b c) = ap a (option b (sameOrIndented >> c)) + +-- | parses with surrounding brackets +indentBrackets + :: (Monad m, Stream s (IndentT m) z) + => GenTokenParser s u (IndentT m) + -> IndentParserT s u m a + -> IndentParserT s u m a +indentBrackets lexer p = withPos $ return id <-/> symbol lexer "[" <+/> p <-/> symbol lexer "]" + +-- | parses with surrounding angle brackets +indentAngles + :: (Monad m, Stream s (IndentT m) z) + => GenTokenParser s u (IndentT m) + -> IndentParserT s u m a + -> IndentParserT s u m a +indentAngles lexer p = withPos $ return id <-/> symbol lexer "<" <+/> p <-/> symbol lexer ">" + +-- | parses with surrounding braces +indentBraces + :: (Monad m, Stream s (IndentT m) z) + => GenTokenParser s u (IndentT m) + -> IndentParserT s u m a + -> IndentParserT s u m a +indentBraces lexer p = withPos $ return id <-/> symbol lexer "{" <+/> p <-/> symbol lexer "}" + +-- | parses with surrounding parentheses +indentParens + :: (Monad m, Stream s (IndentT m) z) + => GenTokenParser s u (IndentT m) + -> IndentParserT s u m a + -> IndentParserT s u m a +indentParens lexer p = withPos $ return id <-/> symbol lexer "(" <+/> p <-/> symbol lexer ")" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/indents-0.3.3/tests/Main.hs new/indents-0.4.0.0/tests/Main.hs --- old/indents-0.3.3/tests/Main.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/indents-0.4.0.0/tests/Main.hs 2016-12-22 17:02:32.000000000 +0100 @@ -0,0 +1,9 @@ +module Main + ( main + ) where + +import qualified Test.Tasty as Tasty +import qualified Text.Parsec.Indent.Tests + +main :: IO () +main = Tasty.defaultMain Text.Parsec.Indent.Tests.tests diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/indents-0.3.3/tests/Text/Parsec/Indent/Tests.hs new/indents-0.4.0.0/tests/Text/Parsec/Indent/Tests.hs --- old/indents-0.3.3/tests/Text/Parsec/Indent/Tests.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/indents-0.4.0.0/tests/Text/Parsec/Indent/Tests.hs 2016-12-22 17:02:32.000000000 +0100 @@ -0,0 +1,68 @@ +module Text.Parsec.Indent.Tests + ( tests + ) where + +import Control.Applicative ((*>), (<*)) +import qualified Test.Tasty as Tasty +import qualified Test.Tasty.HUnit as HUnit +import qualified Text.Parsec as Parsec +import qualified Text.Parsec.Indent as Indent +import Prelude + +tests :: Tasty.TestTree +tests = Tasty.testGroup "Text.Parsec.Indent.Tests" + [ HUnit.testCase "01" $ parseTaxonomyTest + "k \n\ + \ a1 \n\ + \ a2 \n\ + \ b1 \n\ + \ a3 \n\ + \ haha \n\ + \ it \n\ + \ works \n\ + \" $ Just $ + Taxonomy "k" + [ Taxonomy "a1" [] + , Taxonomy "a2" + [ Taxonomy "b1" [] + ] + , Taxonomy "a3" + [ Taxonomy "haha" [] + , Taxonomy "it" [] + , Taxonomy "works" [] + ] + ] + + , HUnit.testCase "02" $ parseTaxonomyTest + " k \n\ + \a \n\ + \" + Nothing + ] + +type Term = String + +data Taxonomy = Taxonomy Term [Taxonomy] deriving (Eq, Show) + +pTerm :: Indent.IndentParser String () String +pTerm = Parsec.many1 Parsec.alphaNum <* Parsec.spaces + +pTaxonomy :: Indent.IndentParser String () Taxonomy +pTaxonomy = Indent.withPos $ do + term <- pTerm + subs <- Parsec.many $ Indent.indented *> pTaxonomy + return $ Taxonomy term subs + +parseTaxonomyTest :: String -> Maybe Taxonomy -> HUnit.Assertion +parseTaxonomyTest src mbResult = case errOrTax of + Left err -> case mbResult of + Just _ -> HUnit.assertFailure (show err) + Nothing -> return () + Right tax -> case mbResult of + Just expected -> HUnit.assertEqual "parseTaxonomyTest" expected tax + Nothing -> HUnit.assertFailure $ + "Expected parse to fail but got: " ++ + show tax + where + errOrTax = Indent.runIndent $ + Parsec.runParserT (pTaxonomy <* Parsec.eof) () "<test>" src