derp-lib (empty) → 0.0.0.1
raw patch · 5 files changed
+212/−0 lines, 5 filesdep +basedep +derpsetup-changed
Dependencies added: base, derp
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- Text/Derp/Char.hs +48/−0
- Text/Derp/Combinator.hs +71/−0
- derp-lib.cabal +61/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Ahn, Ki Yung++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * 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.++ * Neither the name of Ahn, Ki Yung nor the names of other+ 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+OWNER 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
+ Text/Derp/Char.hs view
@@ -0,0 +1,48 @@+module Text.Derp.Char+ ( oneOf, spaces, space, newline, tab+ , upper, lower, alphaNum, digit, hexDigit, octDigit+ , char, satisfy, string+ ) where++import Text.Derp -- hiding (xsR, xsL, xsIn, parens, parensIn+ -- , amb, ambIn, sexp, sexpIn+ -- )++import Text.Derp.Combinator+import Data.Char++token c = Token [c] [c]++oneOf :: [Char] -> Parser Char+oneOf s = foldr1 (<|>) (map char s)++-- noneOf++spaces :: Parser ()+spaces = skipMany space++space, newline, tab :: Parser Char+space = satisfy isSpace+newline = char '\n'+tab = char '\t'++upper, lower, alphaNum, letter, digit, hexDigit, octDigit :: Parser Char+upper = satisfy isUpper+lower = satisfy isLower+alphaNum = satisfy isAlphaNum+letter = satisfy isLetter+digit = satisfy isDigit+hexDigit = satisfy isHexDigit+octDigit = satisfy isOctDigit++char :: Char -> Parser Char+char c = ter [c] ==> head++-- anyChar++satisfy :: (Char -> Bool) -> Parser Char+satisfy f = oneOf (filter f [minBound .. maxBound])++string :: String -> Parser String+string s = foldr (\pc pcs -> pc <~> pcs ==> uncurry (:)) (eps []) (map char s)+
+ Text/Derp/Combinator.hs view
@@ -0,0 +1,71 @@+module Text.Derp.Combinator+ ( (<~), (~>)+ , count, between, option, optionMaybe+ , many, many1, skipMany, skipMany1+ , sepBy, sepBy1, endBy, endBy1, endSepBy, endSepBy1, manyTill+ ) where+import Text.Derp -- hiding (xsR, xsL, xsIn, parens, parensIn+ -- , amb, ambIn, sexp, sexpIn+ -- )++-- import qualified Data.Set as S++tok s = Token s s++infixr 4 <~+infixl 4 ~>+a <~ b = a <~> b ==> fst+a ~> b = a <~> b ==> snd++-- choice++count :: Ord a => Int -> Parser a -> Parser [a]+count n p | n > 0 = p <~> count (n-1) p ==> uncurry (:)+ | otherwise = eps []++-- runParse (count 2 (ter "a")) (map tok ["a","a"]) == S.fromList [["a","a"]]++between :: (Ord open, Ord close, Ord a) =>+ Parser open -> Parser close -> Parser a -> Parser a+between open close p = open ~> (p <~ close)++-- runParse (between (ter "(") (ter ")") (many1 $ ter "a")) (map tok ["(","a","a",")"]) == S.fromList [["a","a"]]++option :: Ord a => a -> Parser a -> Parser a+option a p = eps a <|> p++optionMaybe :: Ord a => Parser a -> Parser (Maybe a)+optionMaybe p = eps Nothing <|> (p ==> Just)++-- optional -- what would this even mean?++many, many1 :: Ord a => Parser a -> Parser [a]+many p = eps [] <|> many1 p+many1 p = p <~> many p ==> uncurry (:)++skipMany, skipMany1 :: Ord a => Parser a -> Parser ()+skipMany p = eps () <|> skipMany1 p+skipMany1 p = p ~> skipMany p++sepBy, sepBy1 :: (Ord a, Ord sep) => Parser a -> Parser sep -> Parser [a]+sepBy p sep = eps [] <|> sepBy1 p sep+sepBy1 p sep = p <~> option [] (sep ~> sepBy1 p sep) ==> uncurry (:)++endBy, endBy1 :: (Ord a, Ord sep) => Parser a -> Parser sep -> Parser [a]+endBy p sep = eps [] <|> endBy1 p sep+endBy1 p sep = (p <~ sep) <~> endBy p sep ==> uncurry (:)++endSepBy, endSepBy1 :: (Ord a, Ord sep) => Parser a -> Parser sep -> Parser [a]+endSepBy p sep = eps [] <|> endSepBy1 p sep+endSepBy1 p sep = sepBy1 p sep <~ optionMaybe sep++manyTill :: (Ord a, Ord end) => Parser a -> Parser end -> Parser [a]+manyTill p end = many p <~ end++-- chainl+-- chainr+-- chainl1+-- chainr1+-- eof+-- lookAhead -- this is not meaningul in derp+-- anyToken
+ derp-lib.cabal view
@@ -0,0 +1,61 @@+-- derp-lib.cabal auto-generated by cabal init. For additional+-- options, see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name: derp-lib++-- The package version. See the Haskell package versioning policy+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for+-- standards guiding when and how versions should be incremented.+Version: 0.0.0.1++-- A short (one-line) description of the package.+Synopsis: combinators based on parsing with derivatives (derp) package++-- A longer description of the package.+-- Description: ++-- URL for the project homepage or repository.+Homepage: http://darcsden.com/kyagrd/derp-lib++-- The license under which the package is released.+License: BSD3++-- The file containing the license text.+License-file: LICENSE++-- The package author(s).+Author: Ahn, Ki Yung++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer: kya@pdx.edu++-- A copyright notice.+-- Copyright: ++Category: Text++Build-type: Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files: ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version: >=1.2+++Library+ -- Modules exported by the library.+ Exposed-modules: Text.Derp.Combinator, Text.Derp.Char+ + -- Packages needed in order to build this package.+ Build-depends: base < 5, derp+ + -- Modules not exported by this package.+ -- Other-modules: + + -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+ -- Build-tools: +