packages feed

units-attoparsec (empty) → 1.0

raw patch · 5 files changed

+415/−0 lines, 5 filesdep +attoparsecdep +basedep +template-haskellsetup-changed

Dependencies added: attoparsec, base, template-haskell, text, units, units-defs

Files

+ Data/Units/SI/Prefixes/Attoparsec/Text.hs view
@@ -0,0 +1,95 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE NoMonomorphismRestriction #-}+module Data.Units.SI.Prefixes.Attoparsec.Text+  ( decaP+  , hectoP+  , kiloP+  , megaP+  , gigaP+  , teraP+  , petaP+  , exaP+  , zettaP+  , yottaP+  , deciP+  , centiP+  , milliP+  , microP+  , nanoP+  , picoP+  , femtoP+  , attoP+  , zeptoP+  , yoctoP+  ) where++import Control.Applicative+import Data.Attoparsec.Text hiding (Number)+import Data.Metrology.SI.Mono+import Data.Units.SI.Prefixes ()+import Data.Text (Text)++(>~) :: Char -> b -> Parser b+a >~  b = char a   >> return b+(>>~):: Text -> b  -> Parser b+a >>~ b = string a >> return b++decaP :: Parser Deca+decaP = "da" >>~ Deca++hectoP :: Parser Hecto+hectoP = 'h' >~ Hecto++kiloP :: Parser Kilo+kiloP = 'k' >~ Kilo++megaP :: Parser Mega+megaP = 'M' >~ Mega++gigaP :: Parser Giga+gigaP = 'G' >~ Giga++teraP :: Parser Tera+teraP = 'T' >~ Tera++petaP :: Parser Peta+petaP = 'P' >~ Peta++exaP :: Parser Exa+exaP = 'E' >~ Exa++zettaP :: Parser Zetta+zettaP = 'Z' >~ Zetta++yottaP :: Parser Yotta+yottaP = 'Y' >~ Yotta++deciP :: Parser Deci+deciP = 'd' >~ Deci++centiP :: Parser Centi+centiP = 'c' >~ Centi++milliP :: Parser Milli+milliP = 'm' >~ Milli++microP :: Parser Micro+microP = (char 'μ' <|> char 'u') >> return Micro++nanoP :: Parser Nano+nanoP = 'n' >~ Nano++picoP :: Parser Pico+picoP = 'p' >~ Pico++femtoP :: Parser Femto+femtoP = 'f' >~ Femto++attoP :: Parser Atto+attoP = 'a' >~ Atto++zeptoP :: Parser Zepto+zeptoP = 'z' >~ Zepto++yoctoP :: Parser Yocto+yoctoP = 'y' >~ Yocto
+ Data/Units/SI/Units/Attoparsec/Text.hs view
@@ -0,0 +1,250 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE TypeFamilies, DataKinds, DefaultSignatures, MultiParamTypeClasses,+             ConstraintKinds, UndecidableInstances, FlexibleContexts,+             FlexibleInstances, ScopedTypeVariables, TypeOperators, PolyKinds #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE QuasiQuotes     #-}++module Data.Units.SI.Units.Attoparsec.Text+ ( ParseUnit(..)+ , parseTime++ , gramP+ , meterP+ , metreP+ , secondP+ , minuteP+ , hourP++ , ampereP+ , kelvinP+ , moleP+ , candelaP+ , hertzP+ , literP+ , litreP+ , newtonP+ , pascalP+ , jouleP+ , wattP+ , coloumbP+ , voltP+ , faradP+ , ohmP+ , siemensP+ , weberP+ , teslaP+ , henryP+ , lumenP+ , luxP+ , becquerelP+ , grayP+ , sievertP+ , katalP+ , hectareP+ , tonP+ , tonneP+ )where++import Data.Text (Text)+import Data.Attoparsec.Text hiding (Number)+import Data.Metrology+import qualified Data.Metrology.SI.MonoTypes as Mono+import Data.Units.SI+import Data.Units.SI.Prefixes.Attoparsec.Text++import Data.Metrology.TH++import Control.Applicative+import Control.Monad++class ParseUnit g i where+  parseUnit :: Parser g -> Parser i+++build :: (Subset+            (CanonicalUnitsOfFactors (UnitFactorsOf unit))+            (CanonicalUnitsOfFactors+               (LookupList (DimFactorsOf (DimOfUnit unit)) 'DefaultLCSU)),+          Subset+            (CanonicalUnitsOfFactors+               (LookupList (DimFactorsOf (DimOfUnit unit)) 'DefaultLCSU))+            (CanonicalUnitsOfFactors (UnitFactorsOf unit)),+          Unit unit,+          UnitFactor+            (LookupList (DimFactorsOf (DimOfUnit unit)) 'DefaultLCSU))+      => Double+      -> Parser a+      -> (a -> unit)+      -> Parser (Qu (DimFactorsOf (DimOfUnit unit)) 'DefaultLCSU Double)+build v g p = (\u' -> v % p u') <$> (skipSpace >> g)++parseUnit' g = skipSpace >> double >>=+    (\v -> let+      in msum . fmap (\op -> skipSpace >> op) $+      [ decaP  >>= build v g . (:@)+      , hectoP >>= build v g . (:@)+      , kiloP  >>= build v g . (:@)+      , megaP  >>= build v g . (:@)+      , gigaP  >>= build v g . (:@)+      , teraP  >>= build v g . (:@)+      , petaP  >>= build v g . (:@)+      , exaP   >>= build v g . (:@)+      , zettaP >>= build v g . (:@)+      , yottaP >>= build v g . (:@)+      , deciP  >>= build v g . (:@)+      , centiP >>= build v g . (:@)+      , milliP >>= build v g . (:@)+      , microP >>= build v g . (:@)+      , nanoP  >>= build v g . (:@)+      , picoP  >>= build v g . (:@)+      , femtoP >>= build v g . (:@)+      , attoP  >>= build v g . (:@)+      , zeptoP >>= build v g . (:@)+      , yoctoP >>= build v g . (:@)+      -- No prefix+      , (\u' -> v % u') <$> (skipSpace >> g)+      ]+      )++-- | Since the parser code is highly repetitive, let save some characters+(>~) :: Char -> b -> Parser b+a >~  b = char a   >> return b+(>>~):: Text -> b  -> Parser b+a >>~ b = asciiCI a >> return b++meterP :: Parser Meter+meterP = 'm' >~ Meter++metreP :: Parser Meter+metreP = meterP+++instance ParseUnit Meter $(evalType [t| Mono.Length |])  where+  parseUnit = parseUnit'++gramP :: Parser Gram+gramP = 'g' >~ Gram++instance ParseUnit Gram $(evalType [t| Mono.Mass |]) where+  parseUnit = parseUnit'++secondP :: Parser Second+secondP =   "seconds"   >>~ Second+        <|> "second"    >>~ Second+        <|> "segundos"  >>~ Second+        <|> "segundo"   >>~ Second+        <|> "secs"      >>~ Second+        <|> "sec"       >>~ Second+        <|> 's' >~ Second++instance ParseUnit Second $(evalType [t| Mono.Time |])  where+  parseUnit = parseUnit'++minuteP :: Parser Minute+minuteP =   "minutes" >>~ Minute+        <|> "minutos" >>~ Minute+        <|> "minute"  >>~ Minute+        <|> "minuto"  >>~ Minute+        <|> "min" >>~ Minute++instance ParseUnit Minute $(evalType [t| Mono.Time |])  where+  parseUnit = parseUnit'++hourP :: Parser Hour+hourP =  "hours" >>~ Hour+     <|> "hour"  >>~ Hour+     <|> 'h' >~ Hour++instance ParseUnit Hour $(evalType [t| Mono.Time |])  where+  parseUnit = parseUnit'++parseTime :: Parser Mono.Time+parseTime =  parseUnit secondP+         <|> parseUnit minuteP+         <|> parseUnit hourP++ampereP :: Parser Ampere+ampereP = 'A' >~ Ampere++kelvinP :: Parser Kelvin+kelvinP = 'k' >~ Kelvin++moleP :: Parser Mole+moleP = "mol" >>~ Mole++candelaP :: Parser Candela+candelaP = "cd" >>~ Candela++hertzP :: Parser Hertz+hertzP = "Hz" >>~ Hertz++literP :: Parser Liter+literP = 'l' >~ Liter++litreP :: Parser Liter+litreP = literP++newtonP :: Parser Newton+newtonP = 'N' >~ Newton++pascalP :: Parser Pascal+pascalP = "Pa" >>~ Pascal++jouleP :: Parser Joule+jouleP = 'J' >~ Joule++wattP :: Parser Watt+wattP = 'W' >~ Watt++coloumbP :: Parser Coulomb+coloumbP = 'C' >~ Coulomb++voltP :: Parser Volt+voltP = 'V' >~ Volt++faradP :: Parser Farad+faradP = 'F' >~ Farad++ohmP :: Parser Ohm+ohmP = 'Ω' >~ Ohm++siemensP :: Parser Siemens+siemensP = 'S' >~ Siemens++weberP :: Parser Weber+weberP = "Wb" >>~ Weber++teslaP :: Parser Tesla+teslaP = 'T' >~ Tesla++henryP :: Parser Henry+henryP = 'H' >~ Henry++lumenP :: Parser Lumen+lumenP = "lm" >>~ Lumen++luxP :: Parser Lux+luxP = "lx" >>~ Lux++becquerelP :: Parser Becquerel+becquerelP = "Bq" >>~ Becquerel++grayP :: Parser Gray+grayP = "Gy" >>~ Gray++sievertP :: Parser Sievert+sievertP = "Sv" >>~ Sievert++katalP :: Parser Katal+katalP = "kat" >>~ Katal++hectareP :: Parser Hectare+hectareP = "ha" >>~ Hectare++tonP :: Parser Ton+tonP = 't' >~ Ton++tonneP :: Parser Ton+tonneP = tonP
+ LICENSE view
@@ -0,0 +1,27 @@+Copyright (c) 2014, João Cristóvão+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this+list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright notice,+this list of conditions and the following disclaimer in the documentation+and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of its contributors may be+used to endorse or promote products derived from this software without+specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ units-attoparsec.cabal view
@@ -0,0 +1,41 @@+name:           units-attoparsec+version:        1.0+cabal-version:  >= 1.18+synopsis:       Attoparsec parsers for the units package+homepage:       https://github.com/jcristovao/units-attoparsec+category:       Physics+author:         João Cristóvão <jmacristovao@gmail.com>+maintainer:     João Cristóvão <jmacristovao@gmail.com>+bug-reports:    https://github.com/jcristovao/units-attoparsec/issues+stability:      experimental+--extra-source-files: README.md, CHANGES.md+license:        BSD3+license-file:   LICENSE+build-type:     Simple+description:++    This package provides parsers for the units defined in the+    @units-defs@ package, used with @units@.++    User contributions to this package are strongly encouraged. Please+    submit pull requests!++source-repository head+  type:     git+  location: https://github.com/jcristovao/units-attoparsec.git++library+  build-depends:      +        base       >= 4.7   && < 5+      , units      >= 2.3   && < 2.4+      , units-defs >= 2.0   && < 2.1+      , text       >= 1.1   && < 1.4+      , attoparsec >= 0.11  && < 0.14+      , template-haskell >= 2.8 && < 2.11++  exposed-modules:+    Data.Units.SI.Prefixes.Attoparsec.Text,+    Data.Units.SI.Units.Attoparsec.Text++  --ghc-options: -Wall+  default-language:   Haskell2010