packages feed

record-dot-preprocessor 0.1.1 → 0.1.2

raw patch · 5 files changed

+25/−7 lines, 5 files

Files

CHANGES.txt view
@@ -1,5 +1,9 @@ Changelog for record-dot-preprocessor +0.1.2, released 2018-07-26+    Make qualified types in records work+    Add LINE droppings to get approximate line numbers correct+    Don't depend on anything not imported from Control.Lens 0.1.1, released 2018-05-09     Handle - as an update operator     Be compatible with qualified imports
README.md view
@@ -1,4 +1,4 @@-# record-dot-preprocessor [![Hackage version](https://img.shields.io/hackage/v/record-dot-preprocessor.svg?label=Hackage)](https://hackage.haskell.org/package/record-dot-preprocessor) [![Stackage version](https://www.stackage.org/package/record-dot-preprocessor/badge/lts?label=Stackage)](https://www.stackage.org/package/record-dot-preprocessor) [![Build Status](https://img.shields.io/travis/ndmitchell/record-dot-preprocessor.svg)](https://travis-ci.org/ndmitchell/record-dot-preprocessor)+# record-dot-preprocessor [![Hackage version](https://img.shields.io/hackage/v/record-dot-preprocessor.svg?label=Hackage)](https://hackage.haskell.org/package/record-dot-preprocessor) [![Stackage version](https://www.stackage.org/package/record-dot-preprocessor/badge/nightly?label=Stackage)](https://www.stackage.org/package/record-dot-preprocessor) [![Build Status](https://img.shields.io/travis/ndmitchell/record-dot-preprocessor/master.svg)](https://travis-ci.org/ndmitchell/record-dot-preprocessor)  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. The reason this feature is ubiquitous is because it's _useful_. The `record-dot-preprocessor` brings this feature to Haskell. Some examples: 
record-dot-preprocessor.cabal view
@@ -1,7 +1,7 @@ cabal-version:      >= 1.18 build-type:         Simple name:               record-dot-preprocessor-version:            0.1.1+version:            0.1.2 license:            BSD3 license-file:       LICENSE category:           Development@@ -18,7 +18,7 @@ extra-doc-files:     README.md     CHANGES.txt-tested-with:        GHC==8.4.1, GHC==8.2.2+tested-with:        GHC==8.4.3, GHC==8.2.2  source-repository head     type:     git
src/Edit.hs view
@@ -57,7 +57,7 @@          prefix = "{-# LANGUAGE DuplicateRecordFields, DataKinds, FlexibleInstances, MultiParamTypeClasses, GADTs, OverloadedLabels #-}"         imports = "import qualified GHC.OverloadedLabels as Z; import qualified Control.Lens as Z"-        trailing = "_preprocessor_unused :: (label ~ \"_unused\", Z.IsLabel label a) => a -> (); _preprocessor_unused x = x `seq` (undefined Z.^. undefined) `seq` ()"+        trailing = "_preprocessor_unused :: (label ~ \"_unused\", Z.IsLabel label a) => a -> a; _preprocessor_unused x = let _undef = _undef; _use _ = x in _use (_undef Z.^. _undef)"   continue op (Paren a b c:xs) = Paren a (op b) c : op xs@@ -131,6 +131,10 @@     , let context = ["Functor f", "t1 ~ " ++ ftyp, "t2 ~ t1", "t3 ~ " ++ rtyp]     ] +unwordsDot (x:".":y:zs) = unwordsDot $ (x ++ "." ++ y) : zs+unwordsDot (x:y:zs) = unwordsDot $ (x ++ " " ++ y) : zs+unwordsDot [x] = x+unwordsDot [] = ""   data Record = Record String [String] [(String, String)] -- TypeName TypeArgs [(FieldName, FieldType)]@@ -153,5 +157,5 @@         ctor _ = []          fields ((x,[]):(y,z):rest) = fields $ (x++y,z):rest-        fields ((names, _:typ):rest) = [(name, trim $ dropWhile (== '!') $ unwords $ unparen typ) | Item name <- names] ++ fields rest+        fields ((names, _:typ):rest) = [(name, trim $ dropWhile (== '!') $ unwordsDot $ unparen typ) | Item name <- names] ++ fields rest         fields _ = []
src/Unlexer.hs view
@@ -4,8 +4,18 @@ module Unlexer(unlexer) where  import Lexer+import Data.List  unlexer :: FilePath -> [Lexeme] -> String unlexer src xs =-    "{-# LINE 1 " ++ show src ++ " #-}\n" ++-    concat [lexeme ++ whitespace | Lexeme{..} <- xs]+    dropping 1 +++    go 1 True [(line, lexeme ++ whitespace) | Lexeme{..} <- xs]+    where+        go :: Int -> Bool -> [(Int, String)] -> String+        go doc drp ((i, x):xs) =+            (if doc /= i && i /= 0 && drp then dropping i else "") +++            x +++            go ((if i == 0 then doc else i) + length (filter (== '\n') x)) ("\n" `isSuffixOf` x) xs+        go _ _ [] = ""++        dropping n = "{-# LINE " ++ show n ++ " " ++ show src ++ " #-}\n"