packages feed

staversion 0.1.3.0 → 0.1.3.1

raw patch · 5 files changed

+128/−12 lines, 5 filesdep ~aeson

Dependency ranges changed: aeson

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for staversion +## 0.1.3.1  -- 2017-01-03++* Now staversion can parse the "curly brace" format of .cabal files (to some extent.)+* Confirmed test with `aeson-1.1.0.0`.+ ## 0.1.3.0  -- 2016-12-29  * Now staversion shows the exact resolver for a partial resolver (e.g. "lts-4" -> "lts-4.2")
src/Staversion/Internal/Cabal.hs view
@@ -47,19 +47,31 @@ isLineSpace '\t' = True isLineSpace _ = False +isOpenBrace :: Char -> Bool+isOpenBrace = (== '{')++isCloseBrace :: Char -> Bool+isCloseBrace = (== '}')++isBrace :: Char -> Bool+isBrace c = isOpenBrace c || isCloseBrace c++lengthOf :: (Char -> Bool) -> P.Parser Int+lengthOf p = length <$> (many $ P.satisfy p)+ indent :: P.Parser Int-indent = length <$> (many $ P.satisfy isLineSpace)+indent = lengthOf isLineSpace  finishLine :: P.Parser () finishLine = P.eof <|> void P.eol  emptyLine :: P.Parser ()-emptyLine = indent *> (P.try finishLine <|> comment_line) where-  comment_line = P.string "--" *> P.manyTill P.anyChar finishLine *> pure ()+emptyLine = indent *> (comment_line <|> void P.eol) where+  comment_line = (P.try $ P.string "--") *> P.manyTill P.anyChar P.eol *> pure ()  blockHeadLine :: P.Parser Target blockHeadLine = target <* trail <* finishLine where-  trail = indent+  trail = many $ P.satisfy $ \c -> isLineSpace c || isOpenBrace c   target = target_lib <|> target_exe <|> target_test <|> target_bench   target_lib = P.try (P.string' "library") *> pure TargetLibrary   target_exe = TargetExecutable <$> targetNamed "executable"@@ -84,8 +96,9 @@ fieldBlock :: P.Parser (String, Text) -- ^ (lower-case field name, block content) fieldBlock = impl where   impl = do-    _ <- many $ P.try conditionalLine-    (field_name, level) <- P.try $ fieldStart Nothing+    (field_name, level) <- P.try $ do+      _ <- many $ (P.try emptyLine <|> P.try conditionalLine <|> P.try bracesOnlyLine)+      fieldStart Nothing     field_trail <- P.manyTill P.anyChar finishLine     rest <- remainingLines level     let text_block = T.intercalate "\n" $ map pack (field_trail : rest)@@ -101,6 +114,8 @@         _ <- indent         this_line <- P.manyTill P.anyChar finishLine         go (this_line : cur_lines)+  bracesOnlyLine = indent *> some braceAndSpace *> finishLine+  braceAndSpace = P.satisfy isBrace *> indent  buildDependsLine :: P.Parser [PackageName] buildDependsLine = P.space *> (pname `P.endBy` ignored) where@@ -112,14 +127,15 @@   finishItem = P.eof <|> (void $ P.char ',')  conditionalLine :: P.Parser ()-conditionalLine = void $ indent *> (term "if" <|> term "else") *> P.manyTill P.anyChar finishLine where+conditionalLine = void $ leader *> (term "if" <|> term "else") *> P.manyTill P.anyChar finishLine where+  leader = many $ P.satisfy $ \c -> isLineSpace c || isCloseBrace c   term :: String -> P.Parser ()-  term t = P.try (P.string' t *> P.lookAhead P.space)+  term t = P.try (P.string' t *> P.lookAhead term_sep)+  term_sep = void $ P.satisfy $ \c -> isSpace c || isBrace c  targetBlock :: P.Parser BuildDepends targetBlock = do   target <- P.try blockHeadLine-  _ <- many $ P.try emptyLine   fields <- some fieldBlock   let build_deps_blocks = map snd $ filter (("build-depends" ==) . fst) $ fields   packages <- fmap (nub . concat) $ forM build_deps_blocks $ \block -> do
staversion.cabal view
@@ -1,5 +1,5 @@ name:                   staversion-version:                0.1.3.0+version:                0.1.3.1 author:                 Toshio Ito <debug.ito@gmail.com> maintainer:             Toshio Ito <debug.ito@gmail.com> license:                BSD3@@ -19,7 +19,8 @@                         test/data/aeson_preferred.json,                         test/data/doctest.cabal_test,                         test/data/conduit.cabal_test,-                        test/data/foobar.cabal_test+                        test/data/foobar.cabal_test,+                        test/data/braces.cabal_test                          homepage:               https://github.com/debug-ito/staversion bug-reports:            https://github.com/debug-ito/staversion/issues@@ -45,7 +46,7 @@                         Staversion.Internal.HTTP   build-depends:        base >=4.6 && <4.10,                         unordered-containers >=0.2.3 && <0.3,-                        aeson >=0.8.0 && <1.1,+                        aeson >=0.8.0 && <1.2,                         text >=0.11.3 && <1.3,                         bytestring >=0.10.0 && <0.11,                         yaml >=0.8.3 && <0.9,
test/Staversion/Internal/CabalSpec.hs view
@@ -110,3 +110,23 @@                                       ]                      }       ]++  it ( "should handle format with curly-braces."+       ++ "For now, open braces should be at line ends (except for trailing white spaces),"+       ++ " and close braces should be in their own lines (except for leading white spaces"+       ++ " and trailing else block)"+     ) $ do+    "braces.cabal_test" `shouldBeParsedTo`+      [ BuildDepends { depsTarget = TargetLibrary,+                       depsPackages = [ "pack-a", "pack-b", "pack-c", "pack-d", "pack-e"+                                      ]+                     },+        BuildDepends { depsTarget = TargetExecutable "braces-else",+                       depsPackages = [ "base", "pack-a", "pack-b", "pack-c", "pack-d"+                                      ]+                     },+        BuildDepends { depsTarget = TargetTestSuite "braces-nest",+                       depsPackages = [ "base", "pack-a", "pack-b", "pack-c"+                                      ]+                     }+      ]
+ test/data/braces.cabal_test view
@@ -0,0 +1,74 @@+Name: braces+Version: 0.0.1+Cabal-Version: >= 1.10+License: BSD3+Author:  Toshio Ito+Synopsis: check with braces for section.+Description: For now, open braces must be at line ends (except for trailing white spaces)+             and close braces must be in their own lines (except for leading white+             spaces and trailing 'else' block.)+Category: Example++Flag open-inline {+Description: inline open brace.+Default:     False+}++Flag open-own+{  +description: open brance in its own line.+default: True+}++Library {  +exposed-modules: Hoge+build-depends: pack-a+if flag(open-inline) {+build-depends: pack-b,+  pack-c <5.0 && >=3.2, pack-d+}++if flag(open-own)+{  +build-depends:+  pack-e+}+}++executable braces-else+{  +main-is: Main.hs+build-depends: base+if flag(open-inline) {+build-depends: pack-a+}  else {+build-depends: pack-b+}++if flag(open-own)+{++build-depends: pack-c+}  +else+{+build-depends:+  pack-d++}  +}  ++test-suite braces-nest+  type: exitcode-stdio-1.0+  main-is: Test.hs+  build-depends: base+  if flag(open-inline) {+  build-depends: pack-a+  if flag(open-own)+  {+   build-depends: pack-b > 9.5+     , pack-c ==10.0+  }+  }++