packages feed

grammatical-parsers 0.3.2 → 0.4

raw patch · 17 files changed

+225/−170 lines, 17 filesdep ~parsersdep ~rank2classesPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: parsers, rank2classes

API changes (from Hackage documentation)

- Text.Grampa: showFailure :: (Eq s, TextualMonoid s) => s -> ParseFailure -> Int -> String
+ Text.Grampa: data Position s
+ Text.Grampa: failureDescription :: forall s. (Eq s, IsString s, FactorialMonoid s) => s -> ParseFailure -> Int -> s
+ Text.Grampa: getSourcePos :: (MonoidParsing m, FactorialMonoid s, Functor (m s)) => m s (Position s)
+ Text.Grampa: offsetContext :: (Eq s, IsString s, FactorialMonoid s) => s -> Int -> Int -> s
+ Text.Grampa: offsetLineAndColumn :: (Eq s, IsString s, FactorialMonoid s) => s -> Int -> ([s], Int)
+ Text.Grampa: positionOffset :: FactorialMonoid s => s -> Position s -> Int
- Text.Grampa.ContextFree.Memoizing: FailureInfo :: Word64 -> [String] -> FailureInfo
+ Text.Grampa.ContextFree.Memoizing: FailureInfo :: Int -> [String] -> FailureInfo
- Text.Grampa.ContextFree.SortedMemoizing: FailureInfo :: Word64 -> [String] -> FailureInfo
+ Text.Grampa.ContextFree.SortedMemoizing: FailureInfo :: Int -> [String] -> FailureInfo

Files

CHANGELOG.md view
@@ -1,3 +1,11 @@+Version 0.4+---------------+* Added `Position` and related functions+* Renamed `showFailure` to `failureDescription`+* Faster parsing at the cost of slower compilation+* Replaced Word64 source positions by plain Int+* Fixed Haddock-related compilation warnings+ Version 0.3.2 --------------- * Improved error reporting
grammatical-parsers.cabal view
@@ -1,5 +1,5 @@ name:                grammatical-parsers-version:             0.3.2+version:             0.4 synopsis:            parsers that combine into grammars description:   /Gram/matical-/pa/rsers, or Grampa for short, is a library of parser types whose values are meant to be assigned@@ -13,7 +13,7 @@ author:              Mario Blažević maintainer:          Mario Blažević <blamario@protonmail.com> copyright:           (c) 2017 Mario Blažević-category:            Text+category:            Text, Parsing build-type:          Simple cabal-version:       >=1.10 extra-source-files:  README.md, CHANGELOG.md@@ -41,7 +41,7 @@                        transformers >= 0.5 && < 0.6,                        monoid-subclasses >=0.4 && <0.5,                        parsers < 0.13,-                       rank2classes >= 1.0.2 && < 1.3+                       rank2classes >= 1.0.2 && < 1.4  executable             arithmetic   hs-source-dirs:      examples@@ -50,7 +50,7 @@   default-language:    Haskell2010   build-depends:       base >=4.9 && <5, containers >= 0.5.7.0 && < 0.7,                        parsers < 0.13,-                       rank2classes >= 1.0.2 && < 1.3, grammatical-parsers,+                       rank2classes >= 1.0.2 && < 1.4, grammatical-parsers,                        monoid-subclasses >=0.4 && <0.5  test-suite           quicktests@@ -59,7 +59,7 @@   x-uses-tf:         true   build-depends:     base >=4.9 && < 5, containers >= 0.5.7.0 && < 0.7,                      monoid-subclasses < 0.5, parsers < 0.13,-                     rank2classes >= 1.0.2 && < 1.3, grammatical-parsers,+                     rank2classes >= 1.0.2 && < 1.4, grammatical-parsers,                      QuickCheck >= 2 && < 3, checkers >= 0.4.6 && < 0.5, size-based < 0.2,                      testing-feat >= 1.1 && < 1.2,                      tasty >= 0.7, tasty-quickcheck >= 0.7@@ -74,13 +74,13 @@   default-language:  Haskell2010   main-is:           Doctest.hs   ghc-options:       -threaded -pgmL markdown-unlit-  build-depends:     base, rank2classes, doctest >= 0.8+  build-depends:     base, rank2classes, grammatical-parsers, parsers, doctest >= 0.8  benchmark            benchmarks   type:              exitcode-stdio-1.0   hs-source-dirs:    test, examples   ghc-options:       -O2 -Wall -rtsopts -main-is Benchmark.main-  Build-Depends:     base >=4.9 && < 5, rank2classes >= 1.0.2 && < 1.3, grammatical-parsers,+  Build-Depends:     base >=4.9 && < 5, rank2classes >= 1.0.2 && < 1.4, grammatical-parsers,                      monoid-subclasses >=0.4 && <0.5, parsers < 0.13,                      criterion >= 1.0, deepseq >= 1.1, containers >= 0.5.7.0 && < 0.7, text >= 1.1   main-is:           Benchmark.hs
src/Text/Grampa.hs view
@@ -4,9 +4,9 @@ module Text.Grampa (    -- * Parsing methods    MultiParsing(..),-   showFailure, simply,+   offsetContext, offsetLineAndColumn, positionOffset, failureDescription, simply,    -- * Types-   Grammar, GrammarBuilder, ParseResults, ParseFailure(..), Ambiguous(..),+   Grammar, GrammarBuilder, ParseResults, ParseFailure(..), Ambiguous(..), Position,    -- * Parser combinators and primitives    GrammarParsing(..), MonoidParsing(..), AmbiguousParsing(..), Lexical(..),    module Text.Parser.Char,@@ -14,17 +14,18 @@    module Text.Parser.LookAhead) where -import Data.List (intercalate)+import Data.List (intersperse) import Data.Monoid ((<>)) import qualified Data.Monoid.Factorial as Factorial-import Data.Monoid.Textual (TextualMonoid, toString)+import Data.Monoid.Factorial (FactorialMonoid)+import Data.String (IsString(fromString)) import Text.Parser.Char (CharParsing(char, notChar, anyChar)) import Text.Parser.Combinators (Parsing((<?>), notFollowedBy, skipMany, skipSome, unexpected)) import Text.Parser.LookAhead (LookAheadParsing(lookAhead))  import qualified Rank2 import Text.Grampa.Class (Lexical(..), MultiParsing(..), GrammarParsing(..), MonoidParsing(..), AmbiguousParsing(..),-                          Ambiguous(..), ParseResults, ParseFailure(..))+                          Ambiguous(..), ParseResults, ParseFailure(..), Position, positionOffset)  -- | A type synonym for a fixed grammar record type @g@ with a given parser type @p@ on input streams of type @s@ type Grammar (g  :: (* -> *) -> *) p s = g (p g s)@@ -43,25 +44,37 @@  -- | Given the textual parse input, the parse failure on the input, and the number of lines preceding the failure to -- show, produce a human-readable failure description.-showFailure :: (Eq s, TextualMonoid s) => s -> ParseFailure -> Int -> String-showFailure input (ParseFailure pos expected) preceding =-   unlines (toString mempty <$> prevLines) <> replicate column ' ' <> "^\n"-   <> "at line " <> show (length allPrevLines) <> ", column " <> show (column+1) <> "\n"-   <> "expected " <> oxfordComma expected-   where oxfordComma [] = []+failureDescription :: forall s. (Eq s, IsString s, FactorialMonoid s) => s -> ParseFailure -> Int -> s+failureDescription input (ParseFailure pos expected) contextLineCount =+   offsetContext input pos contextLineCount+   <> "expected " <> oxfordComma (fromString <$> expected)+   where oxfordComma :: [s] -> s+         oxfordComma [] = ""          oxfordComma [x] = x          oxfordComma [x, y] = x <> " or " <> y-         oxfordComma (x:y:rest) = intercalate ", " (x : y : onLast ("or " <>) rest)+         oxfordComma (x:y:rest) = mconcat (intersperse ", " (x : y : onLast ("or " <>) rest))          onLast _ [] = []          onLast f [x] = [f x]          onLast f (x:xs) = x : onLast f xs-         (allPrevLines, column) = context [] pos (Factorial.split (== "\n") input)-         prevLines = reverse (take (succ preceding) allPrevLines)-         context revLines restCount []-            | restCount > 0 = (["Error: the failure position is beyond the input length"], -1)-            | otherwise = (revLines, restCount)-         context revLines restCount (next:rest)-            | restCount' < 0 = (next:revLines, restCount)-            | otherwise = context (next:revLines) restCount' rest-            where nextLength = Factorial.length next-                  restCount' = restCount - nextLength - 1++-- | Given the parser input, an offset within it, and desired number of context lines, returns a description of+-- the offset position in English.+offsetContext :: (Eq s, IsString s, FactorialMonoid s) => s -> Int -> Int -> s+offsetContext input offset contextLineCount = +   foldMap (<> "\n") prevLines <> fromString (replicate column ' ') <> "^\n"+   <> "at line " <> fromString (show $ length allPrevLines) <> ", column " <> fromString (show $ column+1) <> "\n"+   where (allPrevLines, column) = offsetLineAndColumn input offset+         prevLines = reverse (take contextLineCount allPrevLines)++-- | Given the full input and an offset within it, returns all the input lines up to and including the offset+-- in reverse order, as well as the zero-based column number of the offset+offsetLineAndColumn :: (Eq s, IsString s, FactorialMonoid s) => s -> Int -> ([s], Int)+offsetLineAndColumn input pos = context [] pos (Factorial.split (== "\n") input)+  where context revLines restCount []+          | restCount > 0 = (["Error: the offset is beyond the input length"], -1)+          | otherwise = (revLines, restCount)+        context revLines restCount (next:rest)+          | restCount' < 0 = (next:revLines, restCount)+          | otherwise = context (next:revLines) restCount' rest+          where nextLength = Factorial.length next+                restCount' = restCount - nextLength - 1
src/Text/Grampa/Class.hs view
@@ -1,7 +1,7 @@-{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, DefaultSignatures, RankNTypes, ScopedTypeVariables,-             TypeApplications, TypeFamilies, DeriveDataTypeable #-}-module Text.Grampa.Class (MultiParsing(..), AmbiguousParsing(..), GrammarParsing(..), MonoidParsing(..), Lexical(..),-                          ParseResults, ParseFailure(..), Ambiguous(..), completeParser) where+{-# LANGUAGE AllowAmbiguousTypes, ConstraintKinds, DefaultSignatures, OverloadedStrings, RankNTypes,+             ScopedTypeVariables, TypeApplications, TypeFamilies, DeriveDataTypeable #-}+module Text.Grampa.Class (MultiParsing(..), GrammarParsing(..), AmbiguousParsing(..), MonoidParsing(..), Lexical(..),+                          ParseResults, ParseFailure(..), Ambiguous(..), Position, positionOffset, completeParser) where  import Control.Applicative (Alternative(empty), liftA2, (<|>)) import Data.Char (isAlphaNum, isLetter, isSpace)@@ -14,23 +14,34 @@ import Data.Monoid.Cancellative (LeftReductiveMonoid) import qualified Data.Monoid.Null as Null import Data.Monoid.Null (MonoidNull)+import qualified Data.Monoid.Factorial as Factorial import Data.Monoid.Factorial (FactorialMonoid) import Data.Monoid.Textual (TextualMonoid) import Data.Semigroup (Semigroup((<>)))-import Text.Parser.Combinators (Parsing(notFollowedBy, (<?>)), skipMany)+import Text.Parser.Combinators (Parsing((<?>)), skipMany) import Text.Parser.Char (CharParsing(char))-import Text.Parser.Token (TokenParsing) import GHC.Exts (Constraint)  import qualified Rank2  type ParseResults = Either ParseFailure --- | A 'ParseFailure' contains the offset of the parse failure and the list of things expected at that offset. +-- | A 'ParseFailure' contains the offset of the parse failure and the list of things expected at that offset. data ParseFailure = ParseFailure Int [String] deriving (Eq, Show) --- | An 'Ambiguous' parse result, produced by the 'ambiguous' combinator, contains a 'NonEmpty' list of alternative--- results.+-- | Opaque data type that represents an input position.+newtype Position s = Position{+  -- | The length of the input from the position to end.+  remainderLength :: Int}++-- | Map the position into its offset from the beginning of the full input.+positionOffset :: FactorialMonoid s => s -> Position s -> Int+positionOffset wholeInput = (wholeLength -) . remainderLength+   where wholeLength = Factorial.length wholeInput+{-# INLINE positionOffset #-}++-- | An 'Ambiguous' parse result, produced by the 'ambiguous' combinator, contains a 'NonEmpty' list of+-- alternative results. newtype Ambiguous a = Ambiguous (NonEmpty a) deriving (Data, Eq, Ord, Show, Typeable)  instance Show1 Ambiguous where@@ -91,7 +102,9 @@    recursive :: m g s a -> m g s a     selfReferring = Rank2.cotraverse nonTerminal id+   {-# INLINE selfReferring #-}    fixGrammar = ($ selfReferring)+   {-# INLINE fixGrammar #-}    recursive = id  -- | Methods for parsing monoidal inputs@@ -100,6 +113,8 @@    endOfInput :: FactorialMonoid s => m s ()    -- | Always sucessful parser that returns the remaining input without consuming it.    getInput :: FactorialMonoid s => m s s+   -- | Retrieve the 'Position' the parser has reached in the input source.+   getSourcePos :: FactorialMonoid s => m s (Position s)     -- | A parser that accepts any single input atom.    anyToken :: FactorialMonoid s => m s s@@ -112,9 +127,11 @@    -- given predicate, and returning the input atom that represents the character. A faster version of @singleton <$>    -- satisfyChar p@ and of @satisfy (fromMaybe False p . characterPrefix)@.    satisfyCharInput :: TextualMonoid s => (Char -> Bool) -> m s s-   -- | A parser that succeeds exactly when satisfy doesn't, equivalent to @notFollowedBy . satisfy@+   -- | A parser that succeeds exactly when satisfy doesn't, equivalent to+   -- 'Text.Parser.Combinators.notFollowedBy' @. satisfy@    notSatisfy :: FactorialMonoid s => (s -> Bool) -> m s ()-   -- | A parser that succeeds exactly when satisfyChar doesn't, equivalent to @notFollowedBy . satisfyChar@+   -- | A parser that succeeds exactly when satisfyChar doesn't, equivalent to+   -- 'Text.Parser.Combinators.notFollowedBy' @. satisfyChar@    notSatisfyChar :: TextualMonoid s => (Char -> Bool) -> m s ()     -- | A stateful scanner. The predicate modifies a state argument, and each transformed state is passed to successive@@ -151,16 +168,21 @@    takeCharsWhile1 :: TextualMonoid s => (Char -> Bool) -> m s s    -- | Zero or more argument occurrences like 'many', with concatenated monoidal results.    concatMany :: Monoid a => m s a -> m s a+    default concatMany :: (Monoid a, Alternative (m s)) => m s a -> m s a    concatMany p = go       where go = mappend <$> p <*> go <|> pure mempty+   default getSourcePos :: (FactorialMonoid s, Functor (m s)) => m s (Position s)+   getSourcePos = Position . Factorial.length <$> getInput+   {-# INLINE concatMany #-}+   {-# INLINE getSourcePos #-}  -- | Parsers that can produce alternative parses and collect them into an 'Ambiguous' node class AmbiguousParsing m where    -- | Collect all alternative parses of the same length into a 'NonEmpty' list of results.    ambiguous :: m a -> m (Ambiguous a) --- | If a grammar is 'Lexical', its parsers can instantiate the 'TokenParsing' class.+-- | If a grammar is 'Lexical', its parsers can instantiate the 'Text.Parser.Token.TokenParsing' class. class Lexical (g :: (* -> *) -> *) where    type LexicalConstraint (m :: ((* -> *) -> *) -> * -> * -> *) g s :: Constraint    -- | Always succeeds, consuming all white space and comments
src/Text/Grampa/ContextFree/Continued.hs view
@@ -60,7 +60,7 @@    {-# INLINABLE (<*>) #-}  instance Factorial.FactorialMonoid s => Alternative (Parser g s) where-   empty = Parser (\rest _ failure-> failure $ FailureInfo (fromIntegral $ Factorial.length rest) ["empty"])+   empty = Parser (\rest _ failure-> failure $ FailureInfo (Factorial.length rest) ["empty"])    (<|>) = alt  -- | A named and unconstrained version of the '<|>' operator@@ -94,20 +94,20 @@    try (Parser p) = Parser q       where q :: forall x. s -> (a -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success (failure . rewindFailure)-               where rewindFailure (FailureInfo _pos _msgs) = FailureInfo (fromIntegral $ Factorial.length input) []+               where rewindFailure (FailureInfo _pos _msgs) = FailureInfo (Factorial.length input) []    (<?>) :: forall a. Parser g s a -> String -> Parser g s a    Parser p <?> msg  = Parser q       where q :: forall x. s -> (a -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success (failure . replaceFailure)                where replaceFailure (FailureInfo pos msgs) =-                        FailureInfo pos (if pos == fromIntegral (Factorial.length input) then [msg] else msgs)+                        FailureInfo pos (if pos == Factorial.length input then [msg] else msgs)     eof = endOfInput-   unexpected msg = Parser (\t _ failure -> failure $ FailureInfo (fromIntegral $ Factorial.length t) [msg])+   unexpected msg = Parser (\t _ failure -> failure $ FailureInfo (Factorial.length t) [msg])    notFollowedBy (Parser p) = Parser q       where q :: forall x. s -> (() -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success' failure'-               where success' _ _ _ = failure (FailureInfo (fromIntegral $ Factorial.length input) ["notFollowedBy"])+               where success' _ _ _ = failure (FailureInfo (Factorial.length input) ["notFollowedBy"])                      failure' _ = success () input failure  instance Factorial.FactorialMonoid s => LookAheadParsing (Parser g s) where@@ -135,42 +135,42 @@    endOfInput = Parser p       where p rest success failure                | Null.null rest = success () rest failure-               | otherwise = failure (FailureInfo (fromIntegral $ Factorial.length rest) ["endOfInput"])+               | otherwise = failure (FailureInfo (Factorial.length rest) ["endOfInput"])    getInput = Parser p-      where p rest success failure = success rest mempty failure+      where p rest success failure = success rest rest failure    anyToken = Parser p       where p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) -> success first suffix failure-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["anyToken"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["anyToken"])    satisfy :: forall s. FactorialMonoid s => (s -> Bool) -> Parser g s s    satisfy predicate = Parser p       where p :: forall x. s -> (s -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) | predicate first -> success first suffix failure-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfy"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfy"])    satisfyChar :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s Char    satisfyChar predicate = Parser p       where p :: forall x. s -> (Char -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> success first suffix failure-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfyChar"])    satisfyCharInput :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s s    satisfyCharInput predicate = Parser p       where p :: forall x. s -> (s -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> success (Factorial.primePrefix rest) suffix failure-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfyChar"])    notSatisfy :: forall s. FactorialMonoid s => (s -> Bool) -> Parser g s ()    notSatisfy predicate = Parser p       where p :: forall x. s -> (() -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, _)-                     | predicate first -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["notSatisfy"])+                     | predicate first -> failure (FailureInfo (Factorial.length rest) ["notSatisfy"])                   _ -> success () rest failure    notSatisfyChar :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s ()    notSatisfyChar predicate = Parser p@@ -178,7 +178,7 @@             p rest success failure =                case Textual.characterPrefix rest                of Just first | predicate first-                               -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["notSatisfyChar"])+                               -> failure (FailureInfo (Factorial.length rest) ["notSatisfyChar"])                   _ -> success () rest failure    scan :: forall t s. FactorialMonoid t => s -> (s -> t -> Maybe s) -> Parser g t t    scan s0 f = Parser (p s0)@@ -200,7 +200,7 @@             p rest success failure                | (prefix, suffix) <- Factorial.span predicate rest =                     if Null.null prefix-                    then failure (FailureInfo (fromIntegral $ Factorial.length rest) ["takeWhile1"])+                    then failure (FailureInfo (Factorial.length rest) ["takeWhile1"])                     else success prefix suffix failure    takeCharsWhile :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s s    takeCharsWhile predicate = Parser p@@ -211,7 +211,7 @@    takeCharsWhile1 predicate = Parser p       where p :: forall x. s -> (s -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure-               | Null.null prefix = failure (FailureInfo (fromIntegral $ Factorial.length rest) ["takeCharsWhile1"])+               | Null.null prefix = failure (FailureInfo (Factorial.length rest) ["takeCharsWhile1"])                | otherwise = success prefix suffix failure                where (prefix, suffix) = Textual.span_ False predicate rest    string :: forall s. (Cancellative.LeftReductiveMonoid s, FactorialMonoid s, Show s) => s -> Parser g s s@@ -219,7 +219,7 @@       p :: forall x. s -> (s -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x       p s' success failure          | Just suffix <- Cancellative.stripPrefix s s' = success s suffix failure-         | otherwise = failure (FailureInfo (fromIntegral $ Factorial.length s') ["string " ++ show s])+         | otherwise = failure (FailureInfo (Factorial.length s') ["string " ++ show s])    concatMany :: forall s a. Monoid a => Parser g s a -> Parser g s a    concatMany (Parser p) = Parser q       where q :: forall x. s -> (a -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x@@ -242,4 +242,4 @@                                       (Rank2.fmap (<* endOfInput) g)  fromFailure :: FactorialMonoid s => s -> FailureInfo -> ParseFailure-fromFailure s (FailureInfo pos msgs) = ParseFailure (Factorial.length s - fromIntegral pos + 1) (nub msgs)+fromFailure s (FailureInfo pos msgs) = ParseFailure (Factorial.length s - pos + 1) (nub msgs)
src/Text/Grampa/ContextFree/Continued/Measured.hs view
@@ -60,7 +60,7 @@    {-# INLINABLE (<*>) #-}  instance Factorial.FactorialMonoid s => Alternative (Parser g s) where-   empty = Parser (\rest _ failure-> failure $ FailureInfo (fromIntegral $ Factorial.length rest) ["empty"])+   empty = Parser (\rest _ failure-> failure $ FailureInfo (Factorial.length rest) ["empty"])    (<|>) = alt  -- | A named and unconstrained version of the '<|>' operator@@ -96,20 +96,19 @@    try (Parser p) = Parser q       where q :: forall x. s -> (a -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success (failure . rewindFailure)-               where rewindFailure (FailureInfo _pos _msgs) = FailureInfo (fromIntegral $ Factorial.length input) []+               where rewindFailure (FailureInfo _pos _msgs) = FailureInfo (Factorial.length input) []    (<?>) :: forall a. Parser g s a -> String -> Parser g s a    Parser p <?> msg  = Parser q       where q :: forall x. s -> (a -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success (failure . replaceFailure)                where replaceFailure (FailureInfo pos msgs) =-                        FailureInfo pos (if pos == fromIntegral (Factorial.length input) then [msg] else msgs)+                        FailureInfo pos (if pos == Factorial.length input then [msg] else msgs)    eof = endOfInput-   unexpected msg = Parser (\t _ failure -> failure $ FailureInfo (fromIntegral $ Factorial.length t) [msg])+   unexpected msg = Parser (\t _ failure -> failure $ FailureInfo (Factorial.length t) [msg])    notFollowedBy (Parser p) = Parser q       where q :: forall x. s -> (() -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success' failure'-               where success' _ _ _ _ = failure (FailureInfo (fromIntegral $ Factorial.length input) -                                                             ["notFollowedBy"])+               where success' _ _ _ _ = failure (FailureInfo (Factorial.length input) ["notFollowedBy"])                      failure' _ = success () 0 input failure  instance Factorial.FactorialMonoid s => LookAheadParsing (Parser g s) where@@ -137,43 +136,42 @@    endOfInput = Parser p       where p rest success failure                | Null.null rest = success () 0 rest failure-               | otherwise = failure (FailureInfo (fromIntegral $ Factorial.length rest) ["endOfInput"])+               | otherwise = failure (FailureInfo (Factorial.length rest) ["endOfInput"])    getInput = Parser p-      where p rest success failure = success rest len mempty failure-               where !len = Factorial.length rest+      where p rest success failure = success rest 0 rest failure    anyToken = Parser p       where p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) -> success first 1 suffix failure-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["anyToken"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["anyToken"])    satisfy :: forall s. FactorialMonoid s => (s -> Bool) -> Parser g s s    satisfy predicate = Parser p       where p :: forall x. s -> (s -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) | predicate first -> success first 1 suffix failure-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfy"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfy"])    satisfyChar :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s Char    satisfyChar predicate = Parser p       where p :: forall x. s -> (Char -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> success first 1 suffix failure-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfyChar"])    satisfyCharInput :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s s    satisfyCharInput predicate = Parser p       where p :: forall x. s -> (s -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> success (Factorial.primePrefix rest) 1 suffix failure-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfyChar"])    notSatisfy :: forall s. FactorialMonoid s => (s -> Bool) -> Parser g s ()    notSatisfy predicate = Parser p       where p :: forall x. s -> (() -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, _)-                     | predicate first -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["notSatisfy"])+                     | predicate first -> failure (FailureInfo (Factorial.length rest) ["notSatisfy"])                   _ -> success () 0 rest failure    notSatisfyChar :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s ()    notSatisfyChar predicate = Parser p@@ -181,7 +179,7 @@             p rest success failure =                case Textual.characterPrefix rest                of Just first | predicate first-                               -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["notSatisfyChar"])+                               -> failure (FailureInfo (Factorial.length rest) ["notSatisfyChar"])                   _ -> success () 0 rest failure    scan :: forall t s. FactorialMonoid t => s -> (s -> t -> Maybe s) -> Parser g t t    scan s0 f = Parser (p s0)@@ -209,7 +207,7 @@                | (prefix, suffix) <- Factorial.span predicate rest,                   !len <- Factorial.length prefix =                     if len == 0-                    then failure (FailureInfo (fromIntegral $ Factorial.length rest) ["takeWhile1"])+                    then failure (FailureInfo (Factorial.length rest) ["takeWhile1"])                     else success prefix len suffix failure    takeCharsWhile :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s s    takeCharsWhile predicate = Parser p@@ -221,7 +219,7 @@    takeCharsWhile1 predicate = Parser p       where p :: forall x. s -> (s -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x             p rest success failure-               | Null.null prefix = failure (FailureInfo (fromIntegral $ Factorial.length rest) ["takeCharsWhile1"])+               | Null.null prefix = failure (FailureInfo (Factorial.length rest) ["takeCharsWhile1"])                | otherwise = len `seq` success prefix len suffix failure                where (prefix, suffix) = Textual.span_ False predicate rest                      len = Factorial.length prefix@@ -230,7 +228,7 @@       p :: forall x. s -> (s -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x       p s' success failure          | Just suffix <- Cancellative.stripPrefix s s', !len <- Factorial.length s = success s len suffix failure-         | otherwise = failure (FailureInfo (fromIntegral $ Factorial.length s') ["string " ++ show s])+         | otherwise = failure (FailureInfo (Factorial.length s') ["string " ++ show s])    concatMany :: forall s a. Monoid a => Parser g s a -> Parser g s a    concatMany (Parser p) = Parser q       where q :: forall x. s -> (a -> Int -> s -> (FailureInfo -> x) -> x) -> (FailureInfo -> x) -> x@@ -260,4 +258,4 @@                                       (Rank2.fmap (<* endOfInput) g)  fromFailure :: FactorialMonoid s => s -> FailureInfo -> ParseFailure-fromFailure s (FailureInfo pos msgs) = ParseFailure (Factorial.length s - fromIntegral pos + 1) (nub msgs)+fromFailure s (FailureInfo pos msgs) = ParseFailure (Factorial.length s - pos + 1) (nub msgs)
src/Text/Grampa/ContextFree/LeftRecursive.hs view
@@ -126,11 +126,14 @@                   g (Parser g s) -> s -> g (Compose (Compose ParseResults []) ((,) s))    parsePrefix g input = Rank2.fmap (Compose . Compose . fromResultList input)                                     (snd $ head $ parseRecursive g input)+   {-# INLINE parsePrefix #-}    parseComplete :: (FactorialMonoid s, Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g) =>                     g (Parser g s) -> s -> g (Compose ParseResults [])-   parseComplete g input = Rank2.fmap ((snd <$>) . Compose . fromResultList input)-                                      (snd $ head $ Memoizing.reparseTails close $ parseRecursive g input)-      where close = Rank2.fmap (<* endOfInput) selfReferring+   parseComplete g = \input-> let close = Rank2.fmap (<* endOfInput) selfReferring+                              in Rank2.fmap ((snd <$>) . Compose . fromResultList input)+                                            (snd $ head $ Memoizing.reparseTails close $ parseSeparated g' input)+      where g' = separated g+   {-# INLINE parseComplete #-}  instance GrammarParsing (Fixed Memoizing.Parser) where    type GrammarFunctor (Fixed Memoizing.Parser) = ParserFunctor@@ -358,9 +361,11 @@ primitive _name d0 d1 d = DirectParser{complete= d,                                        direct0= d0,                                        direct1= d1}+{-# INLINE primitive #-}  positivePrimitive :: String -> p g s a -> Fixed p g s a positivePrimitive _name p = PositiveDirectParser{complete= p}+{-# INLINE positivePrimitive #-}  instance (Parsing (p g s), MonoidParsing (Fixed p g)) => Parsing (Fixed p g s) where    eof = primitive "eof" eof empty eof@@ -425,7 +430,7 @@  instance MonoidParsing (Fixed Memoizing.Parser g) where    endOfInput = primitive "endOfInput" endOfInput empty endOfInput-   getInput = primitive "getInput" (endOfInput *> getInput) (notFollowedBy endOfInput *> getInput) getInput+   getInput = primitive "getInput" getInput empty getInput    anyToken = positivePrimitive "anyToken" anyToken    satisfy predicate = positivePrimitive "satisfy" (satisfy predicate)    satisfyChar predicate = positivePrimitive "satisfyChar" (satisfyChar predicate)@@ -473,10 +478,11 @@             d1 = mappend <$> direct1 p <*> cmp             cmp = concatMany (complete p)    {-# INLINABLE string #-}+   {-# INLINABLE concatMany #-}  instance MonoidParsing (Fixed Backtrack.Parser g) where    endOfInput = primitive "endOfInput" endOfInput empty endOfInput-   getInput = primitive "getInput" (endOfInput *> getInput) (notFollowedBy endOfInput *> getInput) getInput+   getInput = primitive "getInput" getInput empty getInput    anyToken = positivePrimitive "anyToken" anyToken    satisfy predicate = positivePrimitive "satisfy" (satisfy predicate)    satisfyChar predicate = positivePrimitive "satisfyChar" (satisfyChar predicate)@@ -524,6 +530,7 @@             d1 = mappend <$> direct1 p <*> cmp             cmp = concatMany (complete p)    {-# INLINABLE string #-}+   {-# INLINABLE concatMany #-}  instance (Parsing (p g s), MonoidParsing (Fixed p g), Show s, TextualMonoid s) => CharParsing (Fixed p g s) where    satisfy = satisfyChar@@ -567,6 +574,7 @@                  Ambiguous ar2 :| [] <- r2 =                     ResultsOfLength l1 s1 (Ambiguous (ar1 <> ar2) :| []) : join rest1 rest2                | otherwise = error "Ambiguous results should be grouped as a single value"+   {-# INLINABLE ambiguous #-}  -- | Turns a context-free parser into a backtracking PEG parser that consumes the longest possible prefix of the list -- of input tails, opposite of 'peg'@@ -614,6 +622,7 @@ parseRecursive :: forall g s. (Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g, FactorialMonoid s) =>                   g (Parser g s) -> s -> [(s, g (ResultList g s))] parseRecursive = parseSeparated . separated+{-# INLINE parseRecursive #-}  separated :: forall g s. (Rank2.Apply g, Rank2.Distributive g, Rank2.Traversable g) =>              g (Parser g s) -> g (SeparatedParser Memoizing.Parser g s)@@ -641,6 +650,7 @@          leftRecursiveDeps (Const True) (Const flags) = Const (dependsOn flags)          leftRecursiveDeps (Const False) (Const flags) = Const (Rank2.fmap (const $ Const False) (dependsOn flags))          intersection (Const a) (Const b) = Const (a && b)+{-# INLINABLE separated #-}  fixDescendants :: forall g. (Rank2.Apply g, Rank2.Traversable g)                      => g (Const (g (Const (ParserFlags g)) -> (ParserFlags g))) -> g (Const (ParserFlags g))@@ -657,6 +667,7 @@             Const (ParserFlags n $ Rank2.liftA2 union old new)          initial = Rank2.liftA2 (\_ (Const n)-> Const (ParserFlags n (const (Const False) Rank2.<$> gf))) gf nullabilities          nullabilities = fixNullabilities gf+{-# INLINABLE fixDescendants #-}  fixNullabilities :: forall g. (Rank2.Apply g, Rank2.Traversable g)                     => g (Const (g (Const (ParserFlags g)) -> (ParserFlags g))) -> g (Const Bool)@@ -668,6 +679,7 @@             where cd' = Rank2.fmap (\(Const f)-> Const (f cd)) gf          agree (Const flags1) (Const flags2) = Const (nullable flags1 == nullable flags2)          initial = const (Const (ParserFlags True (const (Const False) Rank2.<$> gf))) Rank2.<$> gf+{-# INLINABLE fixNullabilities #-}  -- | Parse the given input using a context-free grammar separated into two parts: the first specifying all the -- left-recursive productions, the second all others. The first function argument specifies the left-recursive@@ -741,3 +753,4 @@                   reparse append p = Rank2.apply append (Memoizing.applyParser p $ (s, total) : parsedTail)          recurseMarginal s parsedTail marginal =             flip Memoizing.applyParser ((s, marginal) : parsedTail) Rank2.<$> indirects+{-# NOINLINE parseSeparated #-}
src/Text/Grampa/ContextFree/Memoizing.hs view
@@ -153,7 +153,7 @@ instance MonoidParsing (Parser g) where    endOfInput = eof    getInput = Parser p-      where p rest@((s, _):_) = ResultList (Leaf $ ResultInfo (length rest) [last rest] s) mempty+      where p rest@((s, _):_) = ResultList (Leaf $ ResultInfo 0 rest s) mempty             p [] = ResultList (Leaf $ ResultInfo 0 [] mempty) mempty    anyToken = Parser p       where p rest@((s, _):t) = case splitPrimePrefix s@@ -267,7 +267,7 @@  fromResultList :: FactorialMonoid s => s -> ResultList g s r -> ParseResults [(s, r)] fromResultList s (ResultList EmptyTree (FailureInfo pos msgs)) =-   Left (ParseFailure (length s - fromIntegral pos + 1) (nub msgs))+   Left (ParseFailure (length s - pos + 1) (nub msgs)) fromResultList _ (ResultList rl _failure) = Right (f <$> toList rl)    where f (ResultInfo _ ((s, _):_) r) = (s, r)          f (ResultInfo _ [] r) = (mempty, r)
src/Text/Grampa/ContextFree/Parallel.hs view
@@ -129,7 +129,7 @@       where f s | null s = ResultList (Leaf $ ResultInfo s ()) mempty                 | otherwise = ResultList mempty (FailureInfo (Factorial.length s) ["endOfInput"])    getInput = Parser p-      where p s = ResultList (Leaf $ ResultInfo mempty s) mempty+      where p s = ResultList (Leaf $ ResultInfo s s) mempty    anyToken = Parser p       where p s = case Factorial.splitPrimePrefix s                   of Just (first, rest) -> ResultList (Leaf $ ResultInfo rest first) mempty@@ -191,12 +191,12 @@    try (Parser p) = Parser q       where q rest = rewindFailure (p rest)                where rewindFailure (ResultList rl (FailureInfo _pos _msgs)) =-                        ResultList rl (FailureInfo (fromIntegral $ Factorial.length rest) [])+                        ResultList rl (FailureInfo (Factorial.length rest) [])    Parser p <?> msg  = Parser q       where q rest = replaceFailure (p rest)                where replaceFailure (ResultList EmptyTree (FailureInfo pos msgs)) =                         ResultList EmptyTree (FailureInfo pos $-                                              if pos == fromIntegral (Factorial.length rest) then [msg] else msgs)+                                              if pos == Factorial.length rest then [msg] else msgs)                      replaceFailure rl = rl    notFollowedBy (Parser p) = Parser (\input-> rewind input (p input))       where rewind t (ResultList EmptyTree _) = ResultList (Leaf $ ResultInfo t ()) mempty
src/Text/Grampa/ContextFree/SortedMemoizing.hs view
@@ -14,7 +14,7 @@ import Data.Monoid (Monoid(mappend, mempty)) import Data.Monoid.Cancellative (LeftReductiveMonoid (isPrefixOf)) import Data.Monoid.Null (MonoidNull(null))-import Data.Monoid.Factorial (FactorialMonoid(length, splitPrimePrefix))+import Data.Monoid.Factorial (FactorialMonoid(splitPrimePrefix)) import Data.Monoid.Textual (TextualMonoid) import qualified Data.Monoid.Factorial as Factorial import qualified Data.Monoid.Textual as Textual@@ -43,7 +43,7 @@  instance Functor (Parser g i) where    fmap f (Parser p) = Parser (fmap f . p)-   {-# INLINABLE fmap #-}+   {-# INLINE fmap #-}  instance Applicative (Parser g i) where    pure a = Parser (\rest-> ResultList [ResultsOfLength 0 rest (a:|[])] mempty)@@ -60,7 +60,8 @@    empty = Parser (\rest-> ResultList mempty $ FailureInfo (genericLength rest) [])    Parser p <|> Parser q = Parser r where       r rest = p rest <> q rest-   {-# INLINABLE (<|>) #-}+   {-# INLINE (<|>) #-}+   {-# INLINABLE empty #-}  infixl 3 <<|> (<<|>) :: Parser g s a -> Parser g s a -> Parser g s a@@ -128,7 +129,7 @@ instance MonoidParsing (Parser g) where    endOfInput = eof    getInput = Parser p-      where p rest@((s, _):_) = ResultList [ResultsOfLength (length rest) [last rest] (s:|[])] mempty+      where p rest@((s, _):_) = ResultList [ResultsOfLength 0 rest (s:|[])] mempty             p [] = ResultList [ResultsOfLength 0 [] (mempty:|[])] mempty    anyToken = Parser p       where p rest@((s, _):t) = case splitPrimePrefix s
src/Text/Grampa/Internal.hs view
@@ -6,7 +6,6 @@ import Data.List (nub) import Data.Monoid (Monoid(mappend, mempty)) import Data.Semigroup (Semigroup((<>)))-import Data.Word (Word64)  import Data.Monoid.Factorial (FactorialMonoid(length)) @@ -14,7 +13,7 @@  import Prelude hiding (length, showList) -data FailureInfo = FailureInfo Word64 [String] deriving (Eq, Show)+data FailureInfo = FailureInfo Int [String] deriving (Eq, Show)  data ResultsOfLength g s r = ResultsOfLength !Int ![(s, g (ResultList g s))] !(NonEmpty r) @@ -27,10 +26,11 @@  fromResultList :: FactorialMonoid s => s -> ResultList g s r -> ParseResults [(s, r)] fromResultList s (ResultList [] (FailureInfo pos msgs)) =-   Left (ParseFailure (length s - fromIntegral pos + 1) (nub msgs))+   Left (ParseFailure (length s - pos + 1) (nub msgs)) fromResultList _ (ResultList rl _failure) = Right (foldMap f rl)    where f (ResultsOfLength _ ((s, _):_) r) = (,) s <$> toList r          f (ResultsOfLength _ [] r) = (,) mempty <$> toList r+{-# INLINABLE fromResultList #-}  instance Semigroup FailureInfo where    FailureInfo pos1 exp1 <> FailureInfo pos2 exp2 = FailureInfo pos' exp'@@ -61,9 +61,11 @@  instance Functor (ResultsOfLength g s) where    fmap f (ResultsOfLength l t r) = ResultsOfLength l t (f <$> r)+   {-# INLINE fmap #-}  instance Functor (ResultList g s) where    fmap f (ResultList l failure) = ResultList ((f <$>) <$> l) failure+   {-# INLINE fmap #-}  instance Semigroup (ResultList g s r) where    ResultList rl1 f1 <> ResultList rl2 f2 = ResultList (join rl1 rl2) (f1 <> f2)
src/Text/Grampa/PEG/Backtrack.hs view
@@ -59,7 +59,7 @@    {-# INLINABLE (<*>) #-}  instance Factorial.FactorialMonoid s => Alternative (Parser g s) where-   empty = Parser (\rest-> NoParse $ FailureInfo (fromIntegral $ Factorial.length rest) ["empty"])+   empty = Parser (\rest-> NoParse $ FailureInfo (Factorial.length rest) ["empty"])    (<|>) = alt  -- | A named and unconstrained version of the '<|>' operator@@ -91,17 +91,17 @@    try (Parser p) = Parser q       where q rest = rewindFailure (p rest)                where rewindFailure (NoParse (FailureInfo _pos _msgs)) =-                        NoParse (FailureInfo (fromIntegral $ Factorial.length rest) [])+                        NoParse (FailureInfo (Factorial.length rest) [])                      rewindFailure parsed = parsed    Parser p <?> msg  = Parser q       where q rest = replaceFailure (p rest)                where replaceFailure (NoParse (FailureInfo pos msgs)) =-                        NoParse (FailureInfo pos $ if pos == fromIntegral (Factorial.length rest) then [msg] else msgs)+                        NoParse (FailureInfo pos $ if pos == Factorial.length rest then [msg] else msgs)                      replaceFailure parsed = parsed    eof = endOfInput-   unexpected msg = Parser (\t-> NoParse $ FailureInfo (fromIntegral $ Factorial.length t) [msg])+   unexpected msg = Parser (\t-> NoParse $ FailureInfo (Factorial.length t) [msg])    notFollowedBy (Parser p) = Parser (\input-> rewind input (p input))-      where rewind t Parsed{} = NoParse (FailureInfo (fromIntegral $ Factorial.length t) ["notFollowedBy"])+      where rewind t Parsed{} = NoParse (FailureInfo (Factorial.length t) ["notFollowedBy"])             rewind t NoParse{} = Parsed () t  instance Factorial.FactorialMonoid s => LookAheadParsing (Parser g s) where@@ -126,37 +126,37 @@    endOfInput = Parser p       where p rest                | Null.null rest = Parsed () rest-               | otherwise = NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["endOfInput"])+               | otherwise = NoParse (FailureInfo (Factorial.length rest) ["endOfInput"])    getInput = Parser p-      where p rest = Parsed rest mempty+      where p rest = Parsed rest rest    anyToken = Parser p       where p rest = case Factorial.splitPrimePrefix rest                      of Just (first, suffix) -> Parsed first suffix-                        _ -> NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["anyToken"])+                        _ -> NoParse (FailureInfo (Factorial.length rest) ["anyToken"])    satisfy predicate = Parser p       where p rest =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) | predicate first -> Parsed first suffix-                  _ -> NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfy"])+                  _ -> NoParse (FailureInfo (Factorial.length rest) ["satisfy"])    satisfyChar predicate = Parser p       where p rest =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> Parsed first suffix-                  _ -> NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> NoParse (FailureInfo (Factorial.length rest) ["satisfyChar"])    satisfyCharInput predicate = Parser p       where p rest =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> Parsed (Factorial.primePrefix rest) suffix-                  _ -> NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> NoParse (FailureInfo (Factorial.length rest) ["satisfyChar"])    notSatisfy predicate = Parser p       where p s = case Factorial.splitPrimePrefix s                   of Just (first, _) -                        | predicate first -> NoParse (FailureInfo (fromIntegral $ Factorial.length s) ["notSatisfy"])+                        | predicate first -> NoParse (FailureInfo (Factorial.length s) ["notSatisfy"])                      _ -> Parsed () s    notSatisfyChar predicate = Parser p       where p s = case Textual.characterPrefix s                   of Just first | predicate first -                                  -> NoParse (FailureInfo (fromIntegral $ Factorial.length s) ["notSatisfyChar"])+                                  -> NoParse (FailureInfo (Factorial.length s) ["notSatisfyChar"])                      _ -> Parsed () s    scan s0 f = Parser (p s0)       where p s rest = Parsed prefix suffix@@ -169,18 +169,18 @@    takeWhile1 predicate = Parser p       where p rest | (prefix, suffix) <- Factorial.span predicate rest =                         if Null.null prefix-                        then NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["takeWhile1"])+                        then NoParse (FailureInfo (Factorial.length rest) ["takeWhile1"])                         else Parsed prefix suffix    takeCharsWhile predicate = Parser p       where p rest | (prefix, suffix) <- Textual.span_ False predicate rest = Parsed prefix suffix    takeCharsWhile1 predicate = Parser p       where p rest | (prefix, suffix) <- Textual.span_ False predicate rest =                      if Null.null prefix-                     then NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["takeCharsWhile1"])+                     then NoParse (FailureInfo (Factorial.length rest) ["takeCharsWhile1"])                      else Parsed prefix suffix    string s = Parser p where       p s' | Just suffix <- Cancellative.stripPrefix s s' = Parsed s suffix-           | otherwise = NoParse (FailureInfo (fromIntegral $ Factorial.length s') ["string " ++ show s])+           | otherwise = NoParse (FailureInfo (Factorial.length s') ["string " ++ show s])    concatMany (Parser p) = Parser q       where q rest = case p rest                      of Parsed prefix suffix -> let Parsed prefix' suffix' = q suffix@@ -204,5 +204,5 @@  fromResult :: FactorialMonoid s => s -> Result g s r -> ParseResults (s, r) fromResult s (NoParse (FailureInfo pos msgs)) =-   Left (ParseFailure (Factorial.length s - fromIntegral pos + 1) (nub msgs))+   Left (ParseFailure (Factorial.length s - pos + 1) (nub msgs)) fromResult _ (Parsed prefix suffix) = Right (suffix, prefix)
src/Text/Grampa/PEG/Backtrack/Measured.hs view
@@ -62,7 +62,7 @@    {-# INLINABLE (<*>) #-}  instance Factorial.FactorialMonoid s => Alternative (Parser g s) where-   empty = Parser (\rest-> NoParse $ FailureInfo (fromIntegral $ Factorial.length rest) ["empty"])+   empty = Parser (\rest-> NoParse $ FailureInfo (Factorial.length rest) ["empty"])    (<|>) = alt  -- | A named and unconstrained version of the '<|>' operator@@ -96,17 +96,17 @@    try (Parser p) = Parser q       where q rest = rewindFailure (p rest)                where rewindFailure (NoParse (FailureInfo _pos _msgs)) =-                        NoParse (FailureInfo (fromIntegral $ Factorial.length rest) [])+                        NoParse (FailureInfo (Factorial.length rest) [])                      rewindFailure parsed = parsed    Parser p <?> msg  = Parser q       where q rest = replaceFailure (p rest)                where replaceFailure (NoParse (FailureInfo pos msgs)) =-                        NoParse (FailureInfo pos $ if pos == fromIntegral (Factorial.length rest) then [msg] else msgs)+                        NoParse (FailureInfo pos $ if pos == Factorial.length rest then [msg] else msgs)                      replaceFailure parsed = parsed    eof = endOfInput-   unexpected msg = Parser (\t-> NoParse $ FailureInfo (fromIntegral $ Factorial.length t) [msg])+   unexpected msg = Parser (\t-> NoParse $ FailureInfo (Factorial.length t) [msg])    notFollowedBy (Parser p) = Parser (\input-> rewind input (p input))-      where rewind t Parsed{} = NoParse (FailureInfo (fromIntegral $ Factorial.length t) ["notFollowedBy"])+      where rewind t Parsed{} = NoParse (FailureInfo (Factorial.length t) ["notFollowedBy"])             rewind t NoParse{} = Parsed 0 () t  instance Factorial.FactorialMonoid s => LookAheadParsing (Parser g s) where@@ -131,37 +131,37 @@    endOfInput = Parser p       where p rest                | Null.null rest = Parsed 0 () rest-               | otherwise = NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["endOfInput"])+               | otherwise = NoParse (FailureInfo (Factorial.length rest) ["endOfInput"])    getInput = Parser p-      where p rest = Parsed (Factorial.length rest) rest mempty+      where p rest = Parsed 0 rest rest    anyToken = Parser p       where p rest = case Factorial.splitPrimePrefix rest                      of Just (first, suffix) -> Parsed 1 first suffix-                        _ -> NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["anyToken"])+                        _ -> NoParse (FailureInfo (Factorial.length rest) ["anyToken"])    satisfy predicate = Parser p       where p rest =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) | predicate first -> Parsed 1 first suffix-                  _ -> NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfy"])+                  _ -> NoParse (FailureInfo (Factorial.length rest) ["satisfy"])    satisfyChar predicate = Parser p       where p rest =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> Parsed 1 first suffix-                  _ -> NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> NoParse (FailureInfo (Factorial.length rest) ["satisfyChar"])    satisfyCharInput predicate = Parser p       where p rest =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> Parsed 1 (Factorial.primePrefix rest) suffix-                  _ -> NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> NoParse (FailureInfo (Factorial.length rest) ["satisfyChar"])    notSatisfy predicate = Parser p       where p s = case Factorial.splitPrimePrefix s                   of Just (first, _) -                        | predicate first -> NoParse (FailureInfo (fromIntegral $ Factorial.length s) ["notSatisfy"])+                        | predicate first -> NoParse (FailureInfo (Factorial.length s) ["notSatisfy"])                      _ -> Parsed 0 () s    notSatisfyChar predicate = Parser p       where p s = case Textual.characterPrefix s                   of Just first | predicate first -                                  -> NoParse (FailureInfo (fromIntegral $ Factorial.length s) ["notSatisfyChar"])+                                  -> NoParse (FailureInfo (Factorial.length s) ["notSatisfyChar"])                      _ -> Parsed 0 () s    scan s0 f = Parser (p s0)       where p s rest = Parsed (Factorial.length prefix) prefix suffix@@ -175,7 +175,7 @@    takeWhile1 predicate = Parser p       where p rest | (prefix, suffix) <- Factorial.span predicate rest =                         if Null.null prefix-                        then NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["takeWhile1"])+                        then NoParse (FailureInfo (Factorial.length rest) ["takeWhile1"])                         else Parsed (Factorial.length prefix) prefix suffix    takeCharsWhile predicate = Parser p       where p rest | (prefix, suffix) <- Textual.span_ False predicate rest = @@ -183,11 +183,11 @@    takeCharsWhile1 predicate = Parser p       where p rest | (prefix, suffix) <- Textual.span_ False predicate rest =                      if Null.null prefix-                     then NoParse (FailureInfo (fromIntegral $ Factorial.length rest) ["takeCharsWhile1"])+                     then NoParse (FailureInfo (Factorial.length rest) ["takeCharsWhile1"])                      else Parsed (Factorial.length prefix) prefix suffix    string s = Parser p where       p s' | Just suffix <- Cancellative.stripPrefix s s' = Parsed l s suffix-           | otherwise = NoParse (FailureInfo (fromIntegral $ Factorial.length s') ["string " ++ show s])+           | otherwise = NoParse (FailureInfo (Factorial.length s') ["string " ++ show s])       l = Factorial.length s    concatMany (Parser p) = Parser q       where q rest = case p rest@@ -212,5 +212,5 @@  fromResult :: FactorialMonoid s => s -> Result g s r -> ParseResults (s, r) fromResult s (NoParse (FailureInfo pos msgs)) =-   Left (ParseFailure (Factorial.length s - fromIntegral pos + 1) (nub msgs))+   Left (ParseFailure (Factorial.length s - pos + 1) (nub msgs)) fromResult _ (Parsed _ prefix suffix) = Right (suffix, prefix)
src/Text/Grampa/PEG/Continued.hs view
@@ -60,7 +60,7 @@    {-# INLINABLE (<*>) #-}  instance Factorial.FactorialMonoid s => Alternative (Parser g s) where-   empty = Parser (\rest _ failure-> failure $ FailureInfo (fromIntegral $ Factorial.length rest) ["empty"])+   empty = Parser (\rest _ failure-> failure $ FailureInfo (Factorial.length rest) ["empty"])    (<|>) = alt  -- | A named and unconstrained version of the '<|>' operator@@ -92,19 +92,19 @@    try (Parser p) = Parser q       where q :: forall x. s -> (a -> s -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success (failure . rewindFailure)-               where rewindFailure (FailureInfo _pos _msgs) = FailureInfo (fromIntegral $ Factorial.length input) []+               where rewindFailure (FailureInfo _pos _msgs) = FailureInfo (Factorial.length input) []    (<?>) :: forall a. Parser g s a -> String -> Parser g s a    Parser p <?> msg  = Parser q       where q :: forall x. s -> (a -> s -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success (failure . replaceFailure)                where replaceFailure (FailureInfo pos msgs) =-                        FailureInfo pos (if pos == fromIntegral (Factorial.length input) then [msg] else msgs)+                        FailureInfo pos (if pos == Factorial.length input then [msg] else msgs)    eof = endOfInput-   unexpected msg = Parser (\t _ failure -> failure $ FailureInfo (fromIntegral $ Factorial.length t) [msg])+   unexpected msg = Parser (\t _ failure -> failure $ FailureInfo (Factorial.length t) [msg])    notFollowedBy (Parser p) = Parser q       where q :: forall x. s -> (() -> s -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success' failure'-               where success' _ _ = failure (FailureInfo (fromIntegral $ Factorial.length input) ["notFollowedBy"])+               where success' _ _ = failure (FailureInfo (Factorial.length input) ["notFollowedBy"])                      failure' _ = success () input  instance Factorial.FactorialMonoid s => LookAheadParsing (Parser g s) where@@ -132,42 +132,42 @@    endOfInput = Parser p       where p rest success failure                | Null.null rest = success () rest-               | otherwise = failure (FailureInfo (fromIntegral $ Factorial.length rest) ["endOfInput"])+               | otherwise = failure (FailureInfo (Factorial.length rest) ["endOfInput"])    getInput = Parser p-      where p rest success _ = success rest mempty+      where p rest success _ = success rest rest    anyToken = Parser p       where p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) -> success first suffix-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["anyToken"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["anyToken"])    satisfy :: forall s. FactorialMonoid s => (s -> Bool) -> Parser g s s    satisfy predicate = Parser p       where p :: forall x. s -> (s -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) | predicate first -> success first suffix-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfy"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfy"])    satisfyChar :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s Char    satisfyChar predicate = Parser p       where p :: forall x. s -> (Char -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> success first suffix-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfyChar"])    satisfyCharInput :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s s    satisfyCharInput predicate = Parser p       where p :: forall x. s -> (s -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> success (Factorial.primePrefix rest) suffix-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfyChar"])    notSatisfy :: forall s. FactorialMonoid s => (s -> Bool) -> Parser g s ()    notSatisfy predicate = Parser p       where p :: forall x. s -> (() -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, _)-                     | predicate first -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["notSatisfy"])+                     | predicate first -> failure (FailureInfo (Factorial.length rest) ["notSatisfy"])                   _ -> success () rest    notSatisfyChar :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s ()    notSatisfyChar predicate = Parser p@@ -175,7 +175,7 @@             p rest success failure =                case Textual.characterPrefix rest                of Just first | predicate first-                               -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["notSatisfyChar"])+                               -> failure (FailureInfo (Factorial.length rest) ["notSatisfyChar"])                   _ -> success () rest    scan :: forall t s. FactorialMonoid t => s -> (s -> t -> Maybe s) -> Parser g t t    scan s0 f = Parser (p s0)@@ -197,7 +197,7 @@             p rest success failure                | (prefix, suffix) <- Factorial.span predicate rest =                     if Null.null prefix-                    then failure (FailureInfo (fromIntegral $ Factorial.length rest) ["takeWhile1"])+                    then failure (FailureInfo (Factorial.length rest) ["takeWhile1"])                     else success prefix suffix    takeCharsWhile :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s s    takeCharsWhile predicate = Parser p@@ -207,7 +207,7 @@    takeCharsWhile1 predicate = Parser p       where p :: forall x. s -> (s -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure-               | Null.null prefix = failure (FailureInfo (fromIntegral $ Factorial.length rest) ["takeCharsWhile1"])+               | Null.null prefix = failure (FailureInfo (Factorial.length rest) ["takeCharsWhile1"])                | otherwise = success prefix suffix                where (prefix, suffix) = Textual.span_ False predicate rest    string :: forall s. (Cancellative.LeftReductiveMonoid s, FactorialMonoid s, Show s) => s -> Parser g s s@@ -215,7 +215,7 @@       p :: forall x. s -> (s -> s -> x) -> (FailureInfo -> x) -> x       p s' success failure          | Just suffix <- Cancellative.stripPrefix s s' = success s suffix-         | otherwise = failure (FailureInfo (fromIntegral $ Factorial.length s') ["string " ++ show s])+         | otherwise = failure (FailureInfo (Factorial.length s') ["string " ++ show s])    concatMany :: forall s a. Monoid a => Parser g s a -> Parser g s a    concatMany (Parser p) = Parser q       where q :: forall x. s -> (a -> s -> x) -> (FailureInfo -> x) -> x@@ -238,4 +238,4 @@                                       (Rank2.fmap (<* endOfInput) g)  fromFailure :: FactorialMonoid s => s -> FailureInfo -> ParseFailure-fromFailure s (FailureInfo pos msgs) = ParseFailure (Factorial.length s - fromIntegral pos + 1) (nub msgs)+fromFailure s (FailureInfo pos msgs) = ParseFailure (Factorial.length s - pos + 1) (nub msgs)
src/Text/Grampa/PEG/Continued/Measured.hs view
@@ -61,7 +61,7 @@    {-# INLINABLE (<*>) #-}  instance Factorial.FactorialMonoid s => Alternative (Parser g s) where-   empty = Parser (\rest _ failure-> failure $ FailureInfo (fromIntegral $ Factorial.length rest) ["empty"])+   empty = Parser (\rest _ failure-> failure $ FailureInfo (Factorial.length rest) ["empty"])    (<|>) = alt  -- | A named and unconstrained version of the '<|>' operator@@ -95,19 +95,19 @@    try (Parser p) = Parser q       where q :: forall x. s -> (a -> Int -> s -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success (failure . rewindFailure)-               where rewindFailure (FailureInfo _pos _msgs) = FailureInfo (fromIntegral $ Factorial.length input) []+               where rewindFailure (FailureInfo _pos _msgs) = FailureInfo (Factorial.length input) []    (<?>) :: forall a. Parser g s a -> String -> Parser g s a    Parser p <?> msg  = Parser q       where q :: forall x. s -> (a -> Int -> s -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success (failure . replaceFailure)                where replaceFailure (FailureInfo pos msgs) =-                        FailureInfo pos (if pos == fromIntegral (Factorial.length input) then [msg] else msgs)+                        FailureInfo pos (if pos == Factorial.length input then [msg] else msgs)    eof = endOfInput-   unexpected msg = Parser (\t _ failure -> failure $ FailureInfo (fromIntegral $ Factorial.length t) [msg])+   unexpected msg = Parser (\t _ failure -> failure $ FailureInfo (Factorial.length t) [msg])    notFollowedBy (Parser p) = Parser q       where q :: forall x. s -> (() -> Int -> s -> x) -> (FailureInfo -> x) -> x             q input success failure = p input success' failure'-               where success' _ _ _ = failure (FailureInfo (fromIntegral $ Factorial.length input) ["notFollowedBy"])+               where success' _ _ _ = failure (FailureInfo (Factorial.length input) ["notFollowedBy"])                      failure' _ = success () 0 input  instance Factorial.FactorialMonoid s => LookAheadParsing (Parser g s) where@@ -135,43 +135,42 @@    endOfInput = Parser p       where p rest success failure                | Null.null rest = success () 0 rest-               | otherwise = failure (FailureInfo (fromIntegral $ Factorial.length rest) ["endOfInput"])+               | otherwise = failure (FailureInfo (Factorial.length rest) ["endOfInput"])    getInput = Parser p-      where p rest success _ = success rest len mempty-               where !len = Factorial.length rest+      where p rest success _ = success rest 0 rest    anyToken = Parser p       where p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) -> success first 1 suffix-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["anyToken"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["anyToken"])    satisfy :: forall s. FactorialMonoid s => (s -> Bool) -> Parser g s s    satisfy predicate = Parser p       where p :: forall x. s -> (s -> Int -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, suffix) | predicate first -> success first 1 suffix-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfy"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfy"])    satisfyChar :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s Char    satisfyChar predicate = Parser p       where p :: forall x. s -> (Char -> Int -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> success first 1 suffix-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfyChar"])    satisfyCharInput :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s s    satisfyCharInput predicate = Parser p       where p :: forall x. s -> (s -> Int -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Textual.splitCharacterPrefix rest                of Just (first, suffix) | predicate first -> success (Factorial.primePrefix rest) 1 suffix-                  _ -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["satisfyChar"])+                  _ -> failure (FailureInfo (Factorial.length rest) ["satisfyChar"])    notSatisfy :: forall s. FactorialMonoid s => (s -> Bool) -> Parser g s ()    notSatisfy predicate = Parser p       where p :: forall x. s -> (() -> Int -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure =                case Factorial.splitPrimePrefix rest                of Just (first, _)-                     | predicate first -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["notSatisfy"])+                     | predicate first -> failure (FailureInfo (Factorial.length rest) ["notSatisfy"])                   _ -> success () 0 rest    notSatisfyChar :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s ()    notSatisfyChar predicate = Parser p@@ -179,7 +178,7 @@             p rest success failure =                case Textual.characterPrefix rest                of Just first | predicate first-                               -> failure (FailureInfo (fromIntegral $ Factorial.length rest) ["notSatisfyChar"])+                               -> failure (FailureInfo (Factorial.length rest) ["notSatisfyChar"])                   _ -> success () 0 rest    scan :: forall t s. FactorialMonoid t => s -> (s -> t -> Maybe s) -> Parser g t t    scan s0 f = Parser (p s0)@@ -206,7 +205,7 @@                | (prefix, suffix) <- Factorial.span predicate rest,                   !len <- Factorial.length prefix =                     if len == 0-                    then failure (FailureInfo (fromIntegral $ Factorial.length rest) ["takeWhile1"])+                    then failure (FailureInfo (Factorial.length rest) ["takeWhile1"])                     else success prefix len suffix    takeCharsWhile :: forall s. TextualMonoid s => (Char -> Bool) -> Parser g s s    takeCharsWhile predicate = Parser p@@ -218,7 +217,7 @@    takeCharsWhile1 predicate = Parser p       where p :: forall x. s -> (s -> Int -> s -> x) -> (FailureInfo -> x) -> x             p rest success failure-               | Null.null prefix = failure (FailureInfo (fromIntegral $ Factorial.length rest) ["takeCharsWhile1"])+               | Null.null prefix = failure (FailureInfo (Factorial.length rest) ["takeCharsWhile1"])                | otherwise = success prefix len suffix                where (prefix, suffix) = Textual.span_ False predicate rest                      !len = Factorial.length prefix@@ -227,7 +226,7 @@       p :: forall x. s -> (s -> Int -> s -> x) -> (FailureInfo -> x) -> x       p s' success failure          | Just suffix <- Cancellative.stripPrefix s s', !len <- Factorial.length s = success s len suffix-         | otherwise = failure (FailureInfo (fromIntegral $ Factorial.length s') ["string " ++ show s])+         | otherwise = failure (FailureInfo (Factorial.length s') ["string " ++ show s])    concatMany :: forall s a. Monoid a => Parser g s a -> Parser g s a    concatMany (Parser p) = Parser q       where q :: forall x. s -> (a -> Int -> s -> x) -> (FailureInfo -> x) -> x@@ -253,4 +252,4 @@                                       (Rank2.fmap (<* endOfInput) g)  fromFailure :: FactorialMonoid s => s -> FailureInfo -> ParseFailure-fromFailure s (FailureInfo pos msgs) = ParseFailure (Factorial.length s - fromIntegral pos + 1) (nub msgs)+fromFailure s (FailureInfo pos msgs) = ParseFailure (Factorial.length s - pos + 1) (nub msgs)
src/Text/Grampa/PEG/Packrat.hs view
@@ -30,15 +30,14 @@ import Text.Grampa.Class (Lexical(..), GrammarParsing(..), MonoidParsing(..), MultiParsing(..),                            ParseResults, ParseFailure(..)) import Text.Grampa.Internal (FailureInfo(..))-import qualified Text.Grampa.PEG.Backtrack as Backtrack (Parser)  data Result g s v = Parsed{parsedPrefix :: !v,                             parsedSuffix :: ![(s, g (Result g s))]}                   | NoParse FailureInfo  -- | Parser type for Parsing Expression Grammars that uses an improved packrat algorithm, with O(1) performance bounds--- but with worse constants and more memory consumption than 'Backtrack.Parser'. The 'parse' function returns an input--- prefix parse paired with the remaining input suffix.+-- but with worse constants and more memory consumption than the backtracking 'Text.Grampa.PEG.Backtrack.Parser'. The+-- 'parse' function returns an input prefix parse paired with the remaining input suffix. newtype Parser g s r = Parser{applyParser :: [(s, g (Result g s))] -> Result g s r}  instance Show1 (Result g s) where@@ -130,7 +129,7 @@                | not (Null.null s) = NoParse (FailureInfo (genericLength rest) ["endOfInput"])             p rest = Parsed () rest    getInput = Parser p-      where p rest@((s, _):_) = Parsed s [last rest]+      where p rest@((s, _):_) = Parsed s rest             p [] = Parsed mempty []    anyToken = Parser p       where p rest@((s, _):t) = case Factorial.splitPrimePrefix s@@ -227,6 +226,6 @@  fromResult :: FactorialMonoid s => s -> Result g s r -> ParseResults (s, r) fromResult s (NoParse (FailureInfo pos msgs)) =-   Left (ParseFailure (Factorial.length s - fromIntegral pos + 1) (nub msgs))+   Left (ParseFailure (Factorial.length s - pos + 1) (nub msgs)) fromResult _ (Parsed prefix []) = Right (mempty, prefix) fromResult _ (Parsed prefix ((s, _):_)) = Right (s, prefix)
test/Test/Examples.hs view
@@ -4,7 +4,7 @@ import Control.Applicative (empty, (<|>)) import Data.Functor.Compose (Compose(..)) import Data.Monoid (Monoid(..), (<>))-import Data.Monoid.Textual (TextualMonoid)+import Data.Monoid.Textual (TextualMonoid, toString) import Text.Parser.Combinators (choice)  import Control.Enumerable (share)@@ -148,7 +148,7 @@                     of Right [r] -> Right r                        Right [] -> Left "Unparseable"                        Right _ -> Left "Ambiguous"-                       Left err -> Left (showFailure s err 3)+                       Left err -> Left (toString mempty $ failureDescription s err 3)  instance Lexical ArithmeticComparisons instance Lexical ArithmeticComparisonsBoolean