packages feed

descrilo 0.1.0.2 → 0.1.0.3

raw patch · 2 files changed

+48/−48 lines, 2 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

- Data.DescriLo: instance Show Description
- Data.DescriLo: instance Show a => Show (Element a)
- Data.DescriLo: name :: Description -> String
- Data.DescriLo: values :: Description -> [(String, String)]
+ Data.DescriLo: [name] :: Description -> String
+ Data.DescriLo: [values] :: Description -> [(String, String)]
+ Data.DescriLo: instance GHC.Show.Show Data.DescriLo.Description
+ Data.DescriLo: instance GHC.Show.Show a => GHC.Show.Show (Data.DescriLo.Element a)

Files

Data/DescriLo.hs view
@@ -38,14 +38,14 @@ import System.IO  data Description =-	Description {-		name :: String,-		values :: [(String,String)]-	}+  Description {+    name :: String,+    values :: [(String,String)]+    }  instance Show Description where-	show Description {name=n, values=vs} =-		"[" ++ n ++ "]\n" ++ foldl (++) "" (map (\(x,y) -> "\t" ++ x ++ " = " ++ y ++ "\n") vs)+  show Description {name=n, values=vs} =+    "[" ++ n ++ "]\n" ++ foldl (++) "" (map (\(x,y) -> "\t" ++ x ++ " = " ++ y ++ "\n") vs)  data Element a = Variable a a | Definition a | Nil deriving Show @@ -57,12 +57,12 @@ trimR (' ':[]) = [] trimR ('\t':[]) = [] trimR (h:r) =-	let trimmed = trimR r in-	case trimmed of-		[] -> [h]-		' ':[] -> [h]-		'\t':[] -> [h]-		a -> h:a+  let trimmed = trimR r in+  case trimmed of+    [] -> [h]+    ' ':[] -> [h]+    '\t':[] -> [h]+    a -> h:a  trim s = trimR $ trimL s @@ -73,8 +73,8 @@ -- loads the given file, using 'defaultName' as the default description name in case the document doesn't start with the definition of one  loadDescriptionFile fname defName = do-	fl <- readFile fname-	return $ loadDescriptionString fl defName+  fl <- readFile fname+  return $ loadDescriptionString fl defName  -- | loads all descriptions from a string --@@ -82,54 +82,54 @@ -- -- behaves just like loadDescriptionFile, but receives a 'String' instead loadDescriptionString string defaultName =-	let lns = lines string in-	loadDescriptions lns Description{name = defaultName, values = []}+  let lns = lines string in+  loadDescriptions lns Description{name = defaultName, values = []}  -- returns a list of descriptions loadDescriptions lns cat = loadDescriptions' lns cat False loadDescriptions' [] cat hasVars = if hasVars then [cat] else [] loadDescriptions' (h:rest) cat hasVars =-	let ln = loadLine h in-	case ln of-		Variable left right ->-			let loaded = loadDescriptions' rest cat True in-			case loaded of-				[] -> [cat{values = [(left,right)]}]-				(rcat:rrest) -> rcat{values = (left,right):values rcat}:rrest-		Definition newName -> (if hasVars then (cat :) else id) $ loadDescriptions' rest Description{name = newName, values = []} False-		Nil -> loadDescriptions' rest cat hasVars+  let ln = loadLine h in+  case ln of+    Variable left right ->+      let loaded = loadDescriptions' rest cat True in+      case loaded of+        [] -> [cat{values = [(left,right)]}]+        (rcat:rrest) -> rcat{values = (left,right):values rcat}:rrest+    Definition newName -> (if hasVars then (cat :) else id) $ loadDescriptions' rest Description{name = newName, values = []} False+    Nil -> loadDescriptions' rest cat hasVars  -- returns an Element loadLine ln =-	case ln of-		' ':rest -> loadLine rest-		'\t':rest -> loadLine rest-		'#':_ -> Nil-		'\n':_ -> Nil-		'[':rest -> Definition $ loadDescription rest-		_ -> loadVariable ln+  case ln of+    ' ':rest -> loadLine rest+    '\t':rest -> loadLine rest+    '#':_ -> Nil+    '\n':_ -> Nil+    '[':rest -> Definition $ loadDescription rest+    _ -> loadVariable ln  loadDescription ln =-	case ln of-		[] -> ""-		']':[] -> ""-		h:rest -> h:loadDescription rest+  case ln of+    [] -> ""+    ']':[] -> ""+    h:rest -> h:loadDescription rest  -- if ln is l = r, returns Variable l r -- trims l and r, so that there are no whitespaces before or after loadVariable ln =-	let (left,right) = loadVariableLeft ln in-	case (trim left, trim right) of-		([],_) -> Nil-		(_,[]) -> Nil-		(a,b) -> Variable a b+  let (left,right) = loadVariableLeft ln in+  case (trim left, trim right) of+    ([],_) -> Nil+    (_,[]) -> Nil+    (a,b) -> Variable a b  loadVariableLeft [] = ([],[]) loadVariableLeft (h:rest) =-	let (left,right) = loadVariableLeft rest in-	case h of-		'=' -> ([], rest)-		_ -> (h:left,loadVariableRight right)+  let (left,right) = loadVariableLeft rest in+  case h of+    '=' -> ([], rest)+    _ -> (h:left,loadVariableRight right)  -- removes comments to the right of the value loadVariableRight [] = []@@ -141,4 +141,4 @@ checkAttribute lval compareF Description{values = (h:r)} = checkAttribute' lval compareF (h:r) checkAttribute' _ _ [] = False checkAttribute' lval compareF ((l,r):rest) =-	if l == lval then compareF r else checkAttribute' lval compareF rest+  if l == lval then compareF r else checkAttribute' lval compareF rest
descrilo.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                descrilo-version:             0.1.0.2+version:             0.1.0.3 synopsis:            Loads a list of items with fields description:         Descrilo is a library that loads a INI-like file as a list of 'Description'S, allowing repeated elements. license:             GPL-3@@ -20,7 +20,7 @@   exposed-modules:     Data.DescriLo   -- other-modules:          -- other-extensions:    -  build-depends:       base >=4.7 && <4.8+  build-depends:       base >=4.8 && <4.9   -- hs-source-dirs:         default-language:    Haskell2010