ChristmasTree-0.2: Alternative approach of 'read' that composes grammars instead of parsers.




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:;filename=GRead.bib

For more documentation see the TTTAS webpage: .


Grammar Description

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


type GReadMsg = Message Token (Maybe Token)Source

Type of error repair messages.

data GReadResult a Source

Type of gread results.


Ok a 
Rep a [GReadMsg] 


Show a => Show (GReadResult a)