record-dot-preprocessor 0.1.4 → 0.1.5
raw patch · 4 files changed
+8/−6 lines, 4 filesdep ~base
Dependency ranges changed: base
Files
- CHANGES.txt +2/−0
- LICENSE +1/−1
- record-dot-preprocessor.cabal +3/−3
- src/Edit.hs +2/−2
CHANGES.txt view
@@ -1,5 +1,7 @@ Changelog for record-dot-preprocessor +0.1.5, released 2019-02-09+ #10, support fields named 'x' 0.1.4, released 2018-09-07 Licensed under BSD-3-Clause OR Apache-2.0 0.1.3, released 2018-07-26
LICENSE view
@@ -1,4 +1,4 @@-Copyright Neil Mitchell 2018.+Copyright Neil Mitchell 2018-2019. Licensed under either of:
record-dot-preprocessor.cabal view
@@ -1,14 +1,14 @@ cabal-version: >= 1.18 build-type: Simple name: record-dot-preprocessor-version: 0.1.4+version: 0.1.5 license: BSD3 x-license: BSD-3-Clause OR Apache-2.0 license-file: LICENSE category: Development author: Neil Mitchell <ndmitchell@gmail.com> maintainer: Neil Mitchell <ndmitchell@gmail.com>-copyright: Neil Mitchell 2018+copyright: Neil Mitchell 2018-2019 synopsis: Preprocessor to allow record.field syntax description: In almost every programming language @a.b@ will get the @b@ field from the @a@ data type, and many different data types can have a @b@ field.@@ -19,7 +19,7 @@ extra-doc-files: README.md CHANGES.txt-tested-with: GHC==8.4.3, GHC==8.2.2+tested-with: GHC==8.6.3, GHC==8.4.4, GHC==8.2.2 source-repository head type: git
src/Edit.hs view
@@ -59,7 +59,7 @@ imports = "import qualified GHC.OverloadedLabels as Z; import qualified Control.Lens as Z" -- if you import two things that have preprocessor_unused, and export them as modules, you don't want them to clash trailing modName = "_preprocessor_unused_" ++ uniq ++ " :: (label ~ \"_unused\", Z.IsLabel label a) => a -> a;" ++- "_preprocessor_unused_" ++ uniq ++ " x = let _undef = _undef; _use _ = x in _use (_undef Z.^. _undef)"+ "_preprocessor_unused_" ++ uniq ++ " _x = let _undef = _undef; _use _ = _x in _use (_undef Z.^. _undef)" where uniq = map (\x -> if isAlphaNum x then x else '_') $ concat $ take 19 $ takeWhile modPart $ map lexeme $ unparen modName modPart x = x == "." || all isUpper (take 1 x) @@ -128,7 +128,7 @@ editAddInstances xs = xs ++ concatMap (\x -> [nl, gen x]) [ "instance (" ++ intercalate ", " context ++ ") => Z.IsLabel \"" ++ fname ++ "\" " ++ "((t1 -> f t2) -> " ++ rtyp ++ " -> f t3) " ++- "where fromLabel = Z.lens (\\x -> " ++ fname ++ " (x :: " ++ rtyp ++ ")) (\\c x -> c{" ++ fname ++ "=x} :: " ++ rtyp ++ ")"+ "where fromLabel = Z.lens (" ++ fname ++ " :: (" ++ rtyp ++ ") -> (" ++ ftyp ++ ")) (\\_c _x -> _c{" ++ fname ++ "=_x} :: " ++ rtyp ++ ")" | Record rname rargs fields <- parseRecords $ map (fmap lexeme) xs , let rtyp = "(" ++ unwords (rname : rargs) ++ ")" , (fname, ftyp) <- fields