language-nix 2.1 → 2.1.0.1
raw patch · 3 files changed
+50/−54 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Language.Nix.Binding: instance Arbitrary Binding
- Language.Nix.Binding: instance Constructor C1_0Binding
- Language.Nix.Binding: instance Datatype D1Binding
- Language.Nix.Binding: instance Eq Binding
- Language.Nix.Binding: instance Generic Binding
- Language.Nix.Binding: instance IsString Binding
- Language.Nix.Binding: instance NFData Binding
- Language.Nix.Binding: instance Ord Binding
- Language.Nix.Binding: instance Show Binding
- Language.Nix.Binding: instance Text Binding
- Language.Nix.Identifier: instance Arbitrary Identifier
- Language.Nix.Identifier: instance Constructor C1_0Identifier
- Language.Nix.Identifier: instance Datatype D1Identifier
- Language.Nix.Identifier: instance Eq Identifier
- Language.Nix.Identifier: instance Generic Identifier
- Language.Nix.Identifier: instance IsString Identifier
- Language.Nix.Identifier: instance NFData Identifier
- Language.Nix.Identifier: instance Ord Identifier
- Language.Nix.Identifier: instance Show Identifier
- Language.Nix.Identifier: instance Text Identifier
- Language.Nix.Path: instance Arbitrary Path
- Language.Nix.Path: instance Constructor C1_0Path
- Language.Nix.Path: instance Datatype D1Path
- Language.Nix.Path: instance Eq Path
- Language.Nix.Path: instance Generic Path
- Language.Nix.Path: instance IsString Path
- Language.Nix.Path: instance NFData Path
- Language.Nix.Path: instance Ord Path
- Language.Nix.Path: instance Show Path
- Language.Nix.Path: instance Text Path
+ Language.Nix.Binding: instance Control.DeepSeq.NFData Language.Nix.Binding.Binding
+ Language.Nix.Binding: instance Data.String.IsString Language.Nix.Binding.Binding
+ Language.Nix.Binding: instance Distribution.Text.Text Language.Nix.Binding.Binding
+ Language.Nix.Binding: instance GHC.Classes.Eq Language.Nix.Binding.Binding
+ Language.Nix.Binding: instance GHC.Classes.Ord Language.Nix.Binding.Binding
+ Language.Nix.Binding: instance GHC.Generics.Constructor Language.Nix.Binding.C1_0Binding
+ Language.Nix.Binding: instance GHC.Generics.Datatype Language.Nix.Binding.D1Binding
+ Language.Nix.Binding: instance GHC.Generics.Generic Language.Nix.Binding.Binding
+ Language.Nix.Binding: instance GHC.Show.Show Language.Nix.Binding.Binding
+ Language.Nix.Binding: instance Test.QuickCheck.Arbitrary.Arbitrary Language.Nix.Binding.Binding
+ Language.Nix.Identifier: instance Control.DeepSeq.NFData Language.Nix.Identifier.Identifier
+ Language.Nix.Identifier: instance Data.String.IsString Language.Nix.Identifier.Identifier
+ Language.Nix.Identifier: instance Distribution.Text.Text Language.Nix.Identifier.Identifier
+ Language.Nix.Identifier: instance GHC.Classes.Eq Language.Nix.Identifier.Identifier
+ Language.Nix.Identifier: instance GHC.Classes.Ord Language.Nix.Identifier.Identifier
+ Language.Nix.Identifier: instance GHC.Generics.Constructor Language.Nix.Identifier.C1_0Identifier
+ Language.Nix.Identifier: instance GHC.Generics.Datatype Language.Nix.Identifier.D1Identifier
+ Language.Nix.Identifier: instance GHC.Generics.Generic Language.Nix.Identifier.Identifier
+ Language.Nix.Identifier: instance GHC.Show.Show Language.Nix.Identifier.Identifier
+ Language.Nix.Identifier: instance Test.QuickCheck.Arbitrary.Arbitrary Language.Nix.Identifier.Identifier
+ Language.Nix.Path: instance Control.DeepSeq.NFData Language.Nix.Path.Path
+ Language.Nix.Path: instance Data.String.IsString Language.Nix.Path.Path
+ Language.Nix.Path: instance Distribution.Text.Text Language.Nix.Path.Path
+ Language.Nix.Path: instance GHC.Classes.Eq Language.Nix.Path.Path
+ Language.Nix.Path: instance GHC.Classes.Ord Language.Nix.Path.Path
+ Language.Nix.Path: instance GHC.Generics.Constructor Language.Nix.Path.C1_0Path
+ Language.Nix.Path: instance GHC.Generics.Datatype Language.Nix.Path.D1Path
+ Language.Nix.Path: instance GHC.Generics.Generic Language.Nix.Path.Path
+ Language.Nix.Path: instance GHC.Show.Show Language.Nix.Path.Path
+ Language.Nix.Path: instance Test.QuickCheck.Arbitrary.Arbitrary Language.Nix.Path.Path
Files
- language-nix.cabal +5/−3
- src/Language/Nix/Identifier.hs +39/−49
- src/Language/Nix/Path.hs +6/−2
language-nix.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.7.0.+-- This file has been generated from package.yaml by hpack version 0.12.0. -- -- see: https://github.com/sol/hpack name: language-nix-version: 2.1+version: 2.1.0.1 synopsis: Data types and useful functions to represent and manipulate the Nix language. description: Data types and useful functions to represent and manipulate the Nix language. category: Distribution, Language@@ -13,7 +13,7 @@ maintainer: simons@cryp.to license: BSD3 license-file: LICENSE-tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2+tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1 build-type: Simple cabal-version: >= 1.10 @@ -38,6 +38,8 @@ Language.Nix.Binding Language.Nix.Identifier Language.Nix.Path+ other-modules:+ Paths_language_nix default-language: Haskell2010 test-suite spec
src/Language/Nix/Identifier.hs view
@@ -4,55 +4,10 @@ {-# LANGUAGE TemplateHaskell #-} module Language.Nix.Identifier- (- -- | Identifiers in Nix are essentially strings. They can be constructed- -- (and viewed) with the 'ident' isomorphism. For the sake of convenience,- -- @Identifier@s are an instance of the 'IsString' class.- --- -- Reasonable people restrict themselves to identifiers of the form- -- @[a-zA-Z_][a-zA-Z0-9_'-]*@, because these don't need quoting. The- -- methods of the 'Text' class can be used to parse and pretty-print an- -- identifier with proper quoting:- --- -- >>> disp (ident # "test")- -- test- -- >>> disp (ident # "foo.bar")- -- "foo.bar"- --- -- prop> \str -> Just (ident # str) == simpleParse (quote str)- -- prop> \i -> Just (i :: Identifier) == simpleParse (display i)- Identifier-- , -- | An isomorphism that allows conversion of 'Identifier' from/to the- -- standard 'String' type via 'review'.- --- -- prop> \str -> fromString str == ident # str- -- prop> \str -> set ident str undefined == ident # str- -- prop> \str -> view ident (review ident str) == str- ident-- , -- | Helper function to quote a given identifier string if necessary.- --- -- >>> putStrLn (quote "abc")- -- abc- -- >>> putStrLn (quote "abc.def")- -- "abc.def"- quote-- , -- | Checks whether a given string needs quoting when interpreted as an- -- 'Identifier'. Simple identifiers that don't need quoting match the- -- regular expression @^[a-zA-Z_][a-zA-Z0-9_'-]*$@.- needsQuoting-- , -- | 'ReadP' parser for simple identifiers, i.e. those that don't need- -- quoting.- parseSimpleIdentifier-- , -- | 'ReadP' parser for quoted identifiers, i.e. those that /do/ need- -- quoting.- parseQuotedIdentifier-- ) where+ ( Identifier, ident, quote, needsQuoting+ , parseSimpleIdentifier, parseQuotedIdentifier+ )+ where import Control.DeepSeq import Control.Lens@@ -65,9 +20,31 @@ import Test.QuickCheck import Text.PrettyPrint as PP +-- | Identifiers in Nix are essentially strings. They can be constructed+-- (and viewed) with the 'ident' isomorphism. For the sake of convenience,+-- @Identifier@s are an instance of the 'IsString' class.+--+-- Reasonable people restrict themselves to identifiers of the form+-- @[a-zA-Z_][a-zA-Z0-9_'-]*@, because these don't need quoting. The+-- methods of the 'Text' class can be used to parse and pretty-print an+-- identifier with proper quoting:+--+-- >>> disp (ident # "test")+-- test+-- >>> disp (ident # "foo.bar")+-- "foo.bar"+--+-- prop> \str -> Just (ident # str) == simpleParse (quote str)+-- prop> \i -> Just (i :: Identifier) == simpleParse (display i) declareLenses [d| newtype Identifier = Identifier { ident :: String } deriving (Show, Eq, Ord, IsString, Generic) |]+-- ^ An isomorphism that allows conversion of 'Identifier' from/to the+-- standard 'String' type via 'review'.+--+-- prop> \str -> fromString str == ident # str+-- prop> \str -> set ident str undefined == ident # str+-- prop> \str -> view ident (review ident str) == str instance NFData Identifier where rnf (Identifier str) = rnf str@@ -80,12 +57,16 @@ disp = view (ident . to quote . to text) parse = parseQuotedIdentifier <++ parseSimpleIdentifier +-- | 'ReadP' parser for simple identifiers, i.e. those that don't need+-- quoting. parseSimpleIdentifier :: ReadP r Identifier parseSimpleIdentifier = do c <- satisfy (\x -> x == '_' || isAlpha x) cs <- munch (\x -> x `elem` "_'-" || isAlphaNum x) return (Identifier (c:cs)) +-- | 'ReadP' parser for quoted identifiers, i.e. those that /do/ need+-- quoting. parseQuotedIdentifier :: ReadP r Identifier parseQuotedIdentifier = Identifier . read . fst <$> gather (between (ReadP.char '"') (ReadP.char '"') (many qString))@@ -99,9 +80,18 @@ c2 <- get return [c1,c2] +-- | Checks whether a given string needs quoting when interpreted as an+-- 'Identifier'. Simple identifiers that don't need quoting match the+-- regular expression @^[a-zA-Z_][a-zA-Z0-9_'-]*$@. needsQuoting :: String -> Bool needsQuoting s = null r || not (any (null . snd) r) where r = readP_to_S parseSimpleIdentifier s +-- | Helper function to quote a given identifier string if necessary.+--+-- >>> putStrLn (quote "abc")+-- abc+-- >>> putStrLn (quote "abc.def")+-- "abc.def" quote :: String -> String quote s = if needsQuoting s then show s else s
src/Language/Nix/Path.hs view
@@ -16,6 +16,9 @@ import Test.QuickCheck import Text.PrettyPrint as PP +-- $setup+-- >>> import Control.Exception+ -- | Paths are non-empty lists of identifiers in Nix. -- -- >>> path # [ident # "yo"]@@ -23,8 +26,9 @@ -- -- Any attempt to construct the empty path throws an 'error': ----- >>> path # []--- Path *** Exception: Nix paths cannot be empty+-- >>> :set -XScopedTypeVariables+-- >>> either (\(_::SomeException) -> "empty paths are illegal") show <$> try (evaluate (path # []))+-- "empty paths are illegal" -- -- Paths can be pretty-printed and parsed with the 'Text' class: --