regex-applicative 0.1 → 0.1.1
raw patch · 5 files changed
+46/−21 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +38/−1
- Text/Regex/Applicative/Implementation.hs +1/−1
- Text/Regex/Applicative/Interface.hs +3/−18
- regex-applicative.cabal +2/−1
- test.hs +2/−0
README.md view
@@ -1,4 +1,41 @@ regex-applicative ================= -*regex-applicative* is a Haskell library for parsing using regular expressions.+*regex-applicative* is aimed to be an efficient and easy to use parsing combinator+library for Haskell based on regular expressions.++Perl programmers often use regular expressions for parsing, even if it is not+an appropriate tool for the job, because Perl has so good support for regexps.++The opposite seems to be valid about Haskell programmers -- they use parsing+combinators (which recognize context-free or even context-sensitive grammars),+even when the language is actually regular!++Hopefully, this library will improve the situation.++Installation+------------+Install this library using `cabal-install` tool:++ cabal update+ cabal install regex-applicative++Documentation+-------------+The [API reference][haddock] is available from Hackage++Other resources+---------------++* [This package on Hackage][hackage]+* [Issue tracker][issues]+* [Repository][github]+* ["A Play on Regular Expressions"][play] paper explains, to some extent,+ how this works+++[haddock]: http://hackage.haskell.org/packages/archive/regex-applicative/latest/doc/html/Text-Regex-Applicative.html+[hackage]: http://hackage.haskell.org/package/regex-applicative+[issues]: https://github.com/feuerbach/regex-applicative/issues+[github]: https://github.com/feuerbach/regex-applicative+[play]: http://sebfisch.github.com/haskell-regexp/regexp-play.pdf
Text/Regex/Applicative/Implementation.hs view
@@ -8,7 +8,7 @@ -- | An applicative functor similar to Maybe, but it's '<|>' method honors -- priority. data Priority a = Priority { priority :: !PrSeq, pValue :: a } | Fail- deriving Functor+ deriving (Functor, Show) type PrSeq = Sequence.Seq PrNum type PrNum = Int
Text/Regex/Applicative/Interface.hs view
@@ -36,20 +36,10 @@ instance Applicative (RE s) where pure x = const x <$> RE epsNode- (RE a1) <*> (RE a2) = RE $ RegexpNode- { active = False- , empty = empty a1 <*> empty a2- , final_ = zero- , reg = App a1 a2- }+ (RE a1) <*> (RE a2) = RE $ appNode a1 a2 instance Alternative (RE s) where- (RE a1) <|> (RE a2) = RE $ RegexpNode- { active = False- , empty = empty a1 `emptyChoice` empty a2- , final_ = zero- , reg = Alt a1 a2- }+ (RE a1) <|> (RE a2) = RE $ altNode a1 a2 empty = error "noMatch" <$> psym (const False) many a = reverse <$> reFoldl (flip (:)) [] a @@ -72,12 +62,7 @@ -- | Greedily matches zero or more symbols, which are combined using the given -- folding function reFoldl :: (b -> a -> b) -> b -> RE s a -> RE s b-reFoldl f b (RE a) = RE $ RegexpNode- { active = False- , empty = pure b- , final_ = zero- , reg = Rep f b a- }+reFoldl f b (RE a) = RE $ repNode f b a -- | Attempts to match a string of symbols against the regular expression (=~) :: [s] -> RE s a -> Maybe a
regex-applicative.cabal view
@@ -7,7 +7,7 @@ -- 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.1+Version: 0.1.1 -- A short (one-line) description of the package. Synopsis: Regex-based parsing with applicative interface@@ -70,3 +70,4 @@ -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source. -- Build-tools: + GHC-Options: -Wall -fno-warn-name-shadowing -fno-warn-missing-signatures
test.hs view
@@ -58,6 +58,7 @@ many ((,,,) <$> many_A_or_B <*> sym 'c' <*> many_A_or_B <*> sym 'c') <*> many_A_or_B +re8 = (,) <$> many (sym 'a' <|> sym 'b') <*> many (sym 'b' <|> sym 'c') prop re f (map f -> s) = reference re s == s =~ re @@ -69,6 +70,7 @@ , depthCheck 10 $ prop re5 a , depthCheck 10 $ prop re6 a , depthCheck 7 $ prop re7 abc+ , depthCheck 7 $ prop re8 abc ] main = do