incremental-parser 0.4.0.2 → 0.5
raw patch · 3 files changed
+47/−37 lines, 3 filesdep +input-parsersPVP ok
version bump matches the API change (PVP)
Dependencies added: input-parsers
API changes (from Hackage documentation)
+ Text.ParserCombinators.Incremental: instance (Data.Monoid.Textual.TextualMonoid s, Data.Semigroup.Cancellative.LeftReductive s, Text.Parser.LookAhead.LookAheadParsing (Text.ParserCombinators.Incremental.Parser t s)) => Text.Parser.Input.InputCharParsing (Text.ParserCombinators.Incremental.Parser t s)
+ Text.ParserCombinators.Incremental: instance (GHC.Base.Alternative (Text.ParserCombinators.Incremental.Parser t s), Data.Monoid.Factorial.FactorialMonoid s, Data.Semigroup.Cancellative.LeftReductive s) => Text.Parser.Input.InputParsing (Text.ParserCombinators.Incremental.Parser t s)
+ Text.ParserCombinators.Incremental: instance (GHC.Base.Alternative (Text.ParserCombinators.Incremental.Parser t s), Data.Monoid.Null.MonoidNull s) => Text.Parser.Deterministic.DeterministicParsing (Text.ParserCombinators.Incremental.Parser t s)
- Text.ParserCombinators.Incremental: string :: (LeftReductiveMonoid s, MonoidNull s, Semigroup s) => s -> Parser t s s
+ Text.ParserCombinators.Incremental: string :: (LeftReductive s, MonoidNull s, Semigroup s) => s -> Parser t s s
- Text.ParserCombinators.Incremental.LeftBiasedLocal: string :: (LeftReductiveMonoid s, MonoidNull s, Semigroup s) => s -> Parser t s s
+ Text.ParserCombinators.Incremental.LeftBiasedLocal: string :: (LeftReductive s, MonoidNull s, Semigroup s) => s -> Parser t s s
- Text.ParserCombinators.Incremental.Symmetric: string :: (LeftReductiveMonoid s, MonoidNull s, Semigroup s) => s -> Parser t s s
+ Text.ParserCombinators.Incremental.Symmetric: string :: (LeftReductive s, MonoidNull s, Semigroup s) => s -> Parser t s s
Files
- incremental-parser.cabal +2/−2
- src/Control/Applicative/Monoid.hs +6/−18
- src/Text/ParserCombinators/Incremental.hs +39/−17
incremental-parser.cabal view
@@ -1,5 +1,5 @@ Name: incremental-parser-Version: 0.4.0.2+Version: 0.5 Cabal-Version: >= 1.10 Build-Type: Simple Synopsis: Generic parser library capable of providing partial results from partial input.@@ -30,7 +30,7 @@ Text.ParserCombinators.Incremental.LeftBiasedLocal, Text.ParserCombinators.Incremental.Symmetric, Control.Applicative.Monoid Build-Depends: base >= 4.9 && < 5, transformers >= 0.5 && < 0.6, parsers < 0.13,- monoid-subclasses < 1.1, rank2classes >= 1.0 && < 1.5+ monoid-subclasses < 1.1, rank2classes >= 1.0 && < 1.5, input-parsers < 0.2 ghc-options: -Wall if impl(ghc >= 7.0.0) default-language: Haskell2010
src/Control/Applicative/Monoid.hs view
@@ -1,17 +1,5 @@ {-- Copyright 2011-2018 Mario Blazevic-- This file is part of the Streaming Component Combinators (SCC) project.-- The SCC project is free software: you can redistribute it and/or modify it under the terms of the GNU General Public- License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later- version.-- SCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.-- You should have received a copy of the GNU General Public License along with SCC. If not, see- <http://www.gnu.org/licenses/>.+ Copyright 2011-2020 Mario Blazevic -} -- | This module defines the 'MonoidApplicative' and 'MonoidAlternative' type classes. Their methods are specialized@@ -23,8 +11,8 @@ ) where -import Control.Applicative (Applicative (pure, (<*>)), Alternative ((<|>), some, many), (<$>))-import Data.Monoid (Monoid, mempty, mappend)+import Control.Applicative (Applicative (pure, (<*>)), Alternative ((<|>)), (<$>))+import Data.Monoid (Monoid, mempty) import Data.Semigroup (Semigroup, (<>)) @@ -34,7 +22,7 @@ (+<*>) :: f (a -> a) -> f a -> f a (+<*>) = (<*>) - -- | Lifted and potentially optimized monoid `mappend` operation from the parameter type.+ -- | Lifted and potentially optimized monoid `Data.Monoid.mappend` operation from the parameter type. infixl 5 >< (><) :: Semigroup a => f a -> f a -> f a a >< b = (<>) <$> a +<*> b@@ -44,13 +32,13 @@ moptional :: (Semigroup a, Monoid a) => f a -> f a moptional x = x <|> pure mempty - -- | Zero or more argument occurrences like 'many', but concatenated.+ -- | Zero or more argument occurrences like 'Control.Applicative.many', but concatenated. concatMany :: (Semigroup a, Monoid a) => f a -> f a concatMany x = many' where many' = some' <|> pure mempty some' = x >< many' - -- | One or more argument occurrences like 'some', but concatenated.+ -- | One or more argument occurrences like 'Control.Applicative.some', but concatenated. concatSome :: (Semigroup a, Monoid a) => f a -> f a concatSome x = some' where many' = some' <|> pure mempty
src/Text/ParserCombinators/Incremental.hs view
@@ -1,17 +1,5 @@ {- Copyright 2010-2020 Mario Blazevic-- This file is part of the Streaming Component Combinators (SCC) project.-- The SCC project is free software: you can redistribute it and/or modify it under the terms of the GNU General Public- License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later- version.-- SCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.-- You should have received a copy of the GNU General Public License along with SCC. If not, see- <http://www.gnu.org/licenses/>. -} -- | This module defines parsing combinators for incremental parsers.@@ -26,7 +14,7 @@ -- -- Implementation is based on Brzozowski derivatives. -{-# LANGUAGE FlexibleContexts, FlexibleInstances, GADTs, RankNTypes, UndecidableInstances #-}+{-# LANGUAGE FlexibleContexts, FlexibleInstances, GADTs, RankNTypes, TypeFamilies, UndecidableInstances #-} module Text.ParserCombinators.Incremental ( -- * The Parser type@@ -47,7 +35,6 @@ ) where -import Prelude hiding (and, null, pred, span, takeWhile) import Control.Applicative (Applicative (pure, (<*>), (*>), (<*)), Alternative ((<|>)), (<$>)) import Control.Applicative.Monoid(MonoidApplicative(..), MonoidAlternative(..)) import Control.Monad.Fail (MonadFail(fail))@@ -59,19 +46,25 @@ import Data.Semigroup (Semigroup(..)) import Data.String (fromString) import Data.Monoid (Monoid, mempty, mappend)-import Data.Monoid.Cancellative (LeftReductiveMonoid, isPrefixOf, stripPrefix)-import Data.Monoid.Factorial (FactorialMonoid, splitPrimePrefix, span, tails)+import Data.Monoid.Factorial (FactorialMonoid, length, span, splitAt, splitPrimePrefix, tails) import Data.Monoid.Null (MonoidNull(null)) import Data.Monoid.Textual (TextualMonoid) import qualified Data.Monoid.Textual as Textual+import Data.Semigroup.Cancellative (LeftReductive, isPrefixOf, stripPrefix) import Text.Parser.Combinators (Parsing) import Text.Parser.Char (CharParsing) import Text.Parser.LookAhead (LookAheadParsing)+import Text.Parser.Deterministic (DeterministicParsing)+import Text.Parser.Input (InputParsing(take), InputCharParsing)+import qualified Text.Parser.Deterministic+import qualified Text.Parser.Input import qualified Text.Parser.Combinators import qualified Text.Parser.Char import qualified Text.Parser.LookAhead import qualified Rank2 +import Prelude hiding (and, length, null, pred, span, splitAt, take, takeWhile)+ -- | The central parser type. Its first parameter is the subtype of the parser, the second is the input monoid type, the -- third the output type. data Parser t s r where@@ -234,11 +227,40 @@ instance (Alternative (Parser t s), MonoidNull s) => LookAheadParsing (Parser t s) where lookAhead = lookAhead +instance (Alternative (Parser t s), MonoidNull s) => DeterministicParsing (Parser t s) where+ (<<|>) = (<<|>)+ instance (Alternative (Parser t s), TextualMonoid s) => CharParsing (Parser t s) where satisfy = fmap (fromMaybe (error "isNothing . characterPrefix") . Textual.characterPrefix) . satisfyChar string s = string (fromString s) *> pure s text t = string (Textual.fromText t) *> pure t +instance (Alternative (Parser t s), FactorialMonoid s, LeftReductive s) => InputParsing (Parser t s) where+ type ParserInput (Parser t s) = s+ getInput = lookAhead acceptAll+ anyToken = anyToken+ take n = more (f . splitAt n)+ where f (prefix, suffix)+ | n' == 0 = Result suffix prefix+ | otherwise = resultPart (prefix <>) (take n')+ where n' = n - length prefix+ satisfy predicate = p+ where p = more (f . splitPrimePrefix)+ f (Just (first, rest)) = if predicate first then Result rest first else Failure "satisfy"+ f Nothing = p+ notSatisfy predicate = p+ where p = Delay mempty (f . splitPrimePrefix)+ f (Just (first, rest)) = if predicate first then Failure "satisfy" else Result rest ()+ f Nothing = p+ string = string+ takeWhile = takeWhile+ takeWhile1 = takeWhile1++instance (TextualMonoid s, LeftReductive s, LookAheadParsing (Parser t s)) => InputCharParsing (Parser t s) where+ satisfyCharInput = satisfyChar+ takeCharsWhile = takeCharsWhile+ takeCharsWhile1 = takeCharsWhile1+ appendIncremental :: (Monoid s, Semigroup r) => Parser t s r -> Parser t s r -> Parser t s r appendIncremental (Result s r) p = resultPart (r <>) (feed s p) appendIncremental (ResultPart r e f) p2 = ResultPart r (appendIncremental e p2) (flip appendIncremental p2 . f)@@ -460,7 +482,7 @@ Nothing -> p -- | A parser that consumes and returns the given prefix of the input.-string :: (LeftReductiveMonoid s, MonoidNull s, Semigroup s) => s -> Parser t s s+string :: (LeftReductive s, MonoidNull s, Semigroup s) => s -> Parser t s s string x | null x = mempty string x = more (\y-> case (stripPrefix x y, stripPrefix y x) of (Just y', _) -> Result y' x