numeric-qq (empty) → 0.1.0
raw patch · 6 files changed
+225/−0 lines, 6 filesdep +HTFdep +basedep +loch-thsetup-changed
Dependencies added: HTF, base, loch-th, placeholders, template-haskell
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- executables/InternalTests.hs +14/−0
- library/NumericQQ.hs +43/−0
- library/NumericQQ/Prelude.hs +63/−0
- numeric-qq.cabal +81/−0
+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2014, Nikita Volkov++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ executables/InternalTests.hs view
@@ -0,0 +1,14 @@+{-# OPTIONS_GHC -F -pgmF htfpp #-}++import Test.Framework+import NumericQQ.Prelude+import NumericQQ++main = htfMain $ htf_thisModulesTests+++test_basic = do+ assertEqual 3 [bin|11|]+ assertEqual 521 [bin|1000001001|]+ assertEqual 3996 [oct|7634|]+ assertEqual 41535 [hex|a23f|]
+ library/NumericQQ.hs view
@@ -0,0 +1,43 @@+module NumericQQ+(+ bin,+ oct,+ hex+)+where++import NumericQQ.Prelude+import Numeric+import Data.Char+import Language.Haskell.TH+import Language.Haskell.TH.Quote+++type Base = Int++bin :: QuasiQuoter+bin = qq 2++oct :: QuasiQuoter+oct = qq 8++hex :: QuasiQuoter+hex = qq 16++qq :: Base -> QuasiQuoter+qq base = QuasiQuoter {quoteExp = exp} where+ exp s = + case parse base s of+ Nothing -> fail $ "A string \"" <> s <> + "\" cannot be parsed as a base-" <> + show base <> " number"+ Just i -> return $ LitE (IntegerL (fromIntegral i))++parse :: Base -> String -> Maybe Int+parse base string = + case readInt base ((< base) . digitToInt) digitToInt string of+ [] -> Nothing+ [(r, "")] -> Just r+ [(_, _)] -> Nothing+ r -> $bug $ "Unexpected parsing result: " <> show r+
+ library/NumericQQ/Prelude.hs view
@@ -0,0 +1,63 @@+module NumericQQ.Prelude+( + module Exports,+ bug,+ bottom,+)+where++-- base+-------------------------+import Prelude as Exports hiding (concat, foldr, mapM_, sequence_, foldl1, maximum, minimum, product, sum, all, and, any, concatMap, elem, foldl, foldr1, notElem, or, mapM, sequence, FilePath, id, (.))+import Control.Monad as Exports hiding (mapM_, sequence_, forM_, msum, mapM, sequence, forM)+import Control.Applicative as Exports+import Control.Arrow as Exports hiding (left, right)+import Control.Category as Exports+import Data.Monoid as Exports+import Data.Foldable as Exports+import Data.Traversable as Exports hiding (for)+import Data.Maybe as Exports+import Data.Either as Exports+import Data.List as Exports hiding (concat, foldr, foldl1, maximum, minimum, product, sum, all, and, any, concatMap, elem, foldl, foldr1, notElem, or, find, maximumBy, minimumBy, mapAccumL, mapAccumR, foldl')+import Data.Tuple as Exports+import Data.Function as Exports hiding ((.), id)+import Data.Ord as Exports (Down(..))+import Data.String as Exports+import Data.Int as Exports+import Data.Word as Exports+import Data.Ratio as Exports+import Data.Bits as Exports+import Data.Fixed as Exports+import Data.Ix as Exports+import Data.Data as Exports+import Text.Read as Exports (readMaybe, readEither)+import Control.Exception as Exports hiding (tryJust, try, assert)+import System.Mem as Exports+import System.Mem.StableName as Exports+import System.Timeout as Exports+import System.Exit as Exports+import System.IO.Unsafe as Exports+import System.IO as Exports (Handle, hClose)+import System.IO.Error as Exports+import Unsafe.Coerce as Exports+import GHC.Conc as Exports+import GHC.Generics as Exports (Generic)+import GHC.IO.Exception as Exports+import Data.IORef as Exports+import Data.STRef as Exports+import Control.Monad.ST as Exports+import Debug.Trace as Exports hiding (traceM)++-- placeholders+-------------------------+import Development.Placeholders as Exports++-- custom+-------------------------+import qualified Debug.Trace.LocationTH++bug = [e| $(Debug.Trace.LocationTH.failure) . (msg <>) |]+ where+ msg = "A \"numeric-qq\" package bug: " :: String++bottom = [e| $bug "Bottom evaluated" |]
+ numeric-qq.cabal view
@@ -0,0 +1,81 @@+name:+ numeric-qq+version:+ 0.1.0+synopsis:+ Quasi-quoters for numbers of different bases+description:+ Quasi-quoters for numbers of different bases+category:+ QuasiQoutes, Numeric+homepage:+ https://github.com/nikita-volkov/numeric-qq +bug-reports:+ https://github.com/nikita-volkov/numeric-qq/issues +author:+ Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+ Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+ (c) 2014, Nikita Volkov+license:+ MIT+license-file:+ LICENSE+build-type:+ Simple+cabal-version:+ >=1.10+++source-repository head+ type:+ git+ location:+ git://github.com/nikita-volkov/numeric-qq.git+++library+ hs-source-dirs:+ library+ other-modules:+ NumericQQ.Prelude+ exposed-modules:+ NumericQQ+ build-depends:+ -- template-haskell:+ template-haskell == 2.*,+ -- debugging:+ loch-th == 0.2.*,+ placeholders == 0.1.*,+ -- general:+ base >= 4.5 && < 5+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFunctor, DeriveGeneric, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators+ default-language:+ Haskell2010+++test-suite internal-tests+ type:+ exitcode-stdio-1.0+ hs-source-dirs:+ executables+ library+ main-is:+ InternalTests.hs+ ghc-options:+ -threaded+ build-depends:+ HTF == 0.11.*,+ -- template-haskell:+ template-haskell == 2.*,+ -- debugging:+ loch-th == 0.2.*,+ placeholders == 0.1.*,+ -- general:+ base >= 4.5 && < 5+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFunctor, DeriveGeneric, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators+ default-language:+ Haskell2010