Earley-0.13.0.1: Parsing all context-free grammars using Earley's algorithm.

Safe HaskellNone
LanguageHaskell2010

Text.Earley.Parser

Description

Parsing.

Synopsis

Documentation

data Report e i Source #

A parsing report, which contains fields that are useful for presenting errors to the user if a parse is deemed a failure. Note however that we get a report even when we successfully parse something.

Constructors

Report 

Fields

  • position :: Int

    The final position in the input (0-based) that the parser reached.

  • expected :: [e]

    The named productions processed at the final position.

  • unconsumed :: i

    The part of the input string that was not consumed, which may be empty.

Instances
(Eq e, Eq i) => Eq (Report e i) Source # 
Instance details

Defined in Text.Earley.Parser.Internal

Methods

(==) :: Report e i -> Report e i -> Bool #

(/=) :: Report e i -> Report e i -> Bool #

(Ord e, Ord i) => Ord (Report e i) Source # 
Instance details

Defined in Text.Earley.Parser.Internal

Methods

compare :: Report e i -> Report e i -> Ordering #

(<) :: Report e i -> Report e i -> Bool #

(<=) :: Report e i -> Report e i -> Bool #

(>) :: Report e i -> Report e i -> Bool #

(>=) :: Report e i -> Report e i -> Bool #

max :: Report e i -> Report e i -> Report e i #

min :: Report e i -> Report e i -> Report e i #

(Read e, Read i) => Read (Report e i) Source # 
Instance details

Defined in Text.Earley.Parser.Internal

(Show e, Show i) => Show (Report e i) Source # 
Instance details

Defined in Text.Earley.Parser.Internal

Methods

showsPrec :: Int -> Report e i -> ShowS #

show :: Report e i -> String #

showList :: [Report e i] -> ShowS #

data Result s e i a Source #

The result of a parse.

Constructors

Ended (Report e i)

The parser ended.

Parsed (ST s [a]) Int i (ST s (Result s e i a))

The parser parsed a number of as. These are given as a computation, ST s [a] that constructs the as when run. We can thus save some work by ignoring this computation if we do not care about the results. The Int is the position in the input where these results were obtained, the i the rest of the input, and the last component is the continuation.

Instances
Functor (Result s e i) Source # 
Instance details

Defined in Text.Earley.Parser.Internal

Methods

fmap :: (a -> b) -> Result s e i a -> Result s e i b #

(<$) :: a -> Result s e i b -> Result s e i a #

type Parser e i a = forall s. i -> ST s (Result s e i a) Source #

parser :: ListLike i t => (forall r. Grammar r (Prod r e t a)) -> Parser e i a Source #

Create a parser from the given grammar.

allParses :: Parser e i a -> i -> ([(a, Int)], Report e i) Source #

Return all parses from the result of a given parser. The result may contain partial parses. The Ints are the position at which a result was produced.

The elements of the returned list of results are sorted by their position in ascending order. If there are multiple results at the same position they are returned in an unspecified order.

fullParses :: ListLike i t => Parser e i a -> i -> ([a], Report e i) Source #

Return all parses that reached the end of the input from the result of a given parser.

If there are multiple results they are returned in an unspecified order.

report :: Parser e i a -> i -> Report e i Source #

See e.g. how far the parser is able to parse the input string before it fails. This can be much faster than getting the parse results for highly ambiguous grammars.