Safe Haskell | None |
---|
Alternative approach of read
that composes grammars instead
of parsers. Grammars describing the data types are composed
dynamically, removing possible left-recursion and combining
common prefixes of alternatives.
The function gread
defined here is able to handle the
associativities defined for infix operators.
The function gread
reads data in linear time, while the
function read
has an exponential behavior in some cases
of data types with infix operators.
Non uniform data types are not supported, because they generate infinite grammars.
The library is documented in the paper: Haskell, do you read me?: constructing and composing efficient top-down parsers at runtime
Bibtex entry: http://www.cs.uu.nl/wiki/bin/viewfile/Center/TTTAS?rev=1;filename=GRead.bib
For more documentation see the TTTAS webpage: http://www.cs.uu.nl/wiki/bin/view/Center/TTTAS .
- module Text.GRead.Grammar
- gread :: Gram a => String -> GReadResult a
- type GReadMsg = Message Token (Maybe Token)
- data GReadResult a
Grammar Description
module Text.GRead.Grammar
Reading Functions
gread :: Gram a => String -> GReadResult aSource
The gread
reads input from a string, which must be
completely consumed by the input process.
Returns Ok value
on a successful parse.
Otherwise returns Rep value msgs
, where the value
results of parsing a repaired input. The list msgs
contains the "corrections" done to the input.
For example, a read
-like implementation can be:
read :: (Gram a) => String -> a read input = case gread input of Ok a -> a Rep _ (m:_) -> error $ show m