packages feed

abnf 0.3.0.0 → 0.3.1.0

raw patch · 3 files changed

+18/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Text.ABNF.Document: lookupDocument :: Text -> Document a -> [Document a]
+ Text.ABNF.Document.Operations: lookupDocument :: Text -> Document a -> [Document a]

Files

abnf.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/  name:                abnf-version:             0.3.0.0+version:             0.3.1.0 synopsis:            Parse ABNF and generate parsers for the specified document description:         You can use this library to parse an ABNF document and                      generate a parser from that ABNF to read a document
src/Text/ABNF/Document.hs view
@@ -27,6 +27,7 @@     , squashDocument     , squashDocumentOn     , squashContent+    , lookupDocument     -- * Parsing documents     -- | Re-exported from "Text.ABNF.Document.Parser"     , generateParser@@ -41,6 +42,7 @@                                      , squashDocument                                      , squashDocumentOn                                      , squashContent+                                     , lookupDocument                                      )  import Text.ABNF.Document.Parser ( generateParser
src/Text/ABNF/Document/Operations.hs view
@@ -11,8 +11,10 @@  module Text.ABNF.Document.Operations where +import Control.Monad (join) import Data.Maybe (catMaybes) import Data.Monoid ((<>))+import qualified Data.Text as Text  import Text.ABNF.Document.Types @@ -51,3 +53,16 @@ squashContent [] = mempty squashContent ((Terminal a):xs) = a <> squashContent xs squashContent ((NonTerminal (Document _ conts)):xs) = squashContent conts <> squashContent xs++-- | Looks up nested 'Document's with a particular identifier.+-- NB: Will not recurse into matching documents.+lookupDocument :: forall a. Text.Text -- ^ Identifier to search for+               -> Document a          -- ^ 'Document' to search in+               -> [Document a]+lookupDocument ident doc@(Document ident2 conts) | ident2 == ident = [doc]+                                                 | otherwise = join $ lookupNT <$> conts+    where+        lookupNT :: Content a -> [Document a]+        lookupNT (Terminal _) = []+        lookupNT (NonTerminal d) = lookupDocument ident d+