incremental-parser 0.3 → 0.3.1
raw patch · 4 files changed
+16/−16 lines, 4 filesdep ~base
Dependency ranges changed: base
Files
- Control/Applicative/Monoid.hs +3/−3
- Test/TestIncrementalParser.hs +4/−4
- Text/ParserCombinators/Incremental.hs +8/−8
- incremental-parser.cabal +1/−1
Control/Applicative/Monoid.hs view
@@ -41,17 +41,17 @@ class (Alternative f, MonoidApplicative f) => MonoidAlternative f where -- | Like 'optional', but restricted to 'Monoid' results.- moptional :: Monoid a => f a -> f a+ moptional :: (Semigroup a, Monoid a) => f a -> f a moptional x = x <|> pure mempty -- | Zero or more argument occurrences like 'many', but concatenated.- concatMany :: Monoid a => f a -> f a+ 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.- concatSome :: Monoid a => f a -> f a+ concatSome :: (Semigroup a, Monoid a) => f a -> f a concatSome x = some' where many' = some' <|> pure mempty some' = x >< many'
Test/TestIncrementalParser.hs view
@@ -55,20 +55,20 @@ instance Show (TestParser a r) where show (TestParser d) = show d -instance (Arbitrary r, Monoid r, Show r) => Arbitrary (TestParser a r) where+instance (Arbitrary r, Semigroup r, Monoid r, Show r) => Arbitrary (TestParser a r) where arbitrary = fmap TestParser arbitrary instance Semigroup a => Semigroup (Described a) where Described d1 p1 <> Described d2 p2 = Described (d1 ++ " <> " ++ d2) (p1 <> p2) -instance Monoid a => Monoid (Described a) where+instance (Semigroup a, Monoid a) => Monoid (Described a) where mempty = Described "mempty" mempty mappend = (<>) instance Semigroup r => Semigroup (TestParser a r) where TestParser d1 <> TestParser d2 = TestParser (d1 <> d2) -instance Monoid r => Monoid (TestParser a r) where+instance (Semigroup r, Monoid r) => Monoid (TestParser a r) where mempty = TestParser mempty mappend = (<>) @@ -257,7 +257,7 @@ canonicalResults p = sort $ nub $ completeResults p -instance forall a r. (Arbitrary r, Monoid r, Show r) => Arbitrary (Described (Parser a [Bool] r)) where+instance forall a r. (Arbitrary r, Semigroup r, Monoid r, Show r) => Arbitrary (Described (Parser a [Bool] r)) where arbitrary = sized $ \n-> if n == 0 then return (Described "empty" failure)
Text/ParserCombinators/Incremental.hs view
@@ -178,7 +178,7 @@ instance (Monoid s, Semigroup r) => Semigroup (Parser t s r) where (<>) = (><) -instance (Monoid s, Monoid r) => Monoid (Parser t s r) where+instance (Monoid s, Monoid r, Semigroup r) => Monoid (Parser t s r) where mempty = return mempty mappend = (><) @@ -187,7 +187,7 @@ concatMany = fst . manies concatSome = snd . manies -manies :: (Alternative (Parser t s), Monoid s, Monoid r) => Parser t s r -> (Parser t s r, Parser t s r)+manies :: (Alternative (Parser t s), Monoid s, Monoid r, Semigroup r) => Parser t s r -> (Parser t s r, Parser t s r) manies p = (many, some) where many = resultPart id (some <|> mempty) some = appendIncremental p many@@ -303,7 +303,7 @@ more = Delay (Failure "more") -- | A parser that fails on any non-empty input and succeeds at its end.-eof :: (MonoidNull s, Monoid r) => Parser t s r+eof :: (MonoidNull s, Monoid r, Semigroup r) => Parser t s r eof = Delay mempty (\s-> if null s then eof else Failure "eof") -- | A parser that accepts any single input atom.@@ -337,7 +337,7 @@ Nothing -> p -- | A parser that consumes and returns the given prefix of the input.-string :: (LeftReductiveMonoid s, MonoidNull s) => s -> Parser t s s+string :: (LeftReductiveMonoid 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@@ -390,22 +390,22 @@ (feed suffix' $ takeCharsWhile pred) -- | Accepts the given number of occurrences of the argument parser.-count :: (Monoid s, Monoid r) => Int -> Parser t s r -> Parser t s r+count :: (Monoid s, Monoid r, Semigroup r) => Int -> Parser t s r -> Parser t s r count n p | n > 0 = p >< count (pred n) p | otherwise = mempty -- | Discards the results of the argument parser.-skip :: (Monoid s, Monoid r) => Parser t s r' -> Parser t s r+skip :: (Monoid s, Monoid r, Semigroup r) => Parser t s r' -> Parser t s r skip p = p *> mempty -- | Repeats matching the first argument until the second one succeeds.-manyTill :: (Monoid s, Monoid r) => Parser t s r -> Parser t s r' -> Parser t s r+manyTill :: (Monoid s, Monoid r, Semigroup r) => Parser t s r -> Parser t s r' -> Parser t s r manyTill next end = if isInfallible next then t1 else t2 where t1 = skip end <<|> appendIncremental next t1 t2 = skip end <<|> append next t2 -- | A parser that accepts and consumes all input.-acceptAll :: Monoid s => Parser t s s+acceptAll :: (Semigroup s, Monoid s) => Parser t s s acceptAll = ResultPart id mempty f where f s = ResultPart (mappend s) mempty f
incremental-parser.cabal view
@@ -1,5 +1,5 @@ Name: incremental-parser-Version: 0.3+Version: 0.3.1 Cabal-Version: >= 1.10 Build-Type: Simple Synopsis: Generic parser library capable of providing partial results from partial input.