network-uri-static (empty) → 0.1.0.0
raw patch · 5 files changed
+133/−0 lines, 5 filesdep +basedep +doctestdep +network-urisetup-changed
Dependencies added: base, doctest, network-uri, template-haskell
Files
- LICENSE +20/−0
- Setup.hs +2/−0
- network-uri-static.cabal +50/−0
- src/Network/URI/Static.hs +55/−0
- test/doctest.hs +6/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Satoshi Nakamura++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
+ network-uri-static.cabal view
@@ -0,0 +1,50 @@+name: network-uri-static+version: 0.1.0.0+synopsis: A small utility to declare type-safe static URIs+description:+ This library helps you declare type-safe static URIs by parsing URIs at compile time.+ .+ You can write static URIs using typed template haskell:+ .+ > url :: URI+ > url = $$(staticURI "http://www.google.com/")+ .+ or using QuasiQuote:+ .+ > url :: URI+ > url = [uri|http://www.google.com/|]+ .+ When you pass a malformed URI to these expressions, they emit an error at compile time.+homepage: http://github.com/snakamura/network-uri-static+license: MIT+license-file: LICENSE+author: Satoshi Nakamura+maintainer: snak@snak.org+copyright: 2015 Satoshi Nakamura+category: Network+build-type: Simple+cabal-version: >= 1.10++bug-reports: https://github.com/snakamura/network-uri-static/issues+source-repository head+ type: git+ location: git://github.com/snakamura/network-uri-static.git++library+ exposed-modules: Network.URI.Static+ other-extensions: RecordWildCards,+ TemplateHaskell,+ ViewPatterns+ build-depends: base >= 4.7 && < 5,+ network-uri >= 2.5 && < 3,+ template-haskell >= 2.9 && < 3+ hs-source-dirs: src+ default-language: Haskell2010++test-suite doctest+ type: exitcode-stdio-1.0+ default-language: Haskell2010+ hs-source-dirs: test+ main-is: doctest.hs+ build-depends: base,+ doctest >= 0.9.3
+ src/Network/URI/Static.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE RecordWildCards, TemplateHaskell, ViewPatterns #-}++module Network.URI.Static+ ( staticURI+ , uri+ ) where++import Language.Haskell.TH (unType)+import Language.Haskell.TH.Lib (TExpQ)+import Language.Haskell.TH.Quote (QuasiQuoter(..))+import Language.Haskell.TH.Syntax (Lift(..))+import Network.URI (URI(..), URIAuth(..), parseURI)++-- $setup+-- >>> :set -XTemplateHaskell+-- >>> :set -XQuasiQuotes++-- | 'staticURI' parses a specified string at compile time+-- and return an expression representing the URI when it's a valid URI.+-- Otherwise, it emits an error.+--+-- >>> $$(staticURI "http://www.google.com/")+-- http://www.google.com/+--+-- >>> $$(staticURI "http://www.google.com/##")+-- <BLANKLINE>+-- <interactive>...+-- ... Invalid URI: http://www.google.com/##+-- ...+staticURI :: String -- ^ String representation of a URI+ -> TExpQ URI -- ^ URI+staticURI (parseURI -> Just uri) = [|| uri ||]+staticURI uri = fail $ "Invalid URI: " ++ uri++instance Lift URI where+ lift (URI {..}) = [| URI {..} |]++instance Lift URIAuth where+ lift (URIAuth {..}) = [| URIAuth {..} |]++-- | 'uri' is a quasi quoter for 'staticURI'.+--+-- >>> [uri|http://www.google.com/|]+-- http://www.google.com/+--+-- >>> [uri|http://www.google.com/##|]+-- <BLANKLINE>+-- <interactive>... Invalid URI: http://www.google.com/##+uri :: QuasiQuoter+uri = QuasiQuoter {+ quoteExp = fmap unType . staticURI,+ quotePat = undefined,+ quoteType = undefined,+ quoteDec = undefined+}
+ test/doctest.hs view
@@ -0,0 +1,6 @@+module Main where++import Test.DocTest (doctest)++main :: IO ()+main = doctest ["src/Network/URI/Static.hs"]