sexpr-0.2.1: S-expression printer and parser

Codec.Sexpr.Parser

Description

All present parsers work on Strings, one character at a time. The canonical encoding is clearly susceptible to efficient parsing as a Lazy ByteString.

This package also includes the Read instance for Sexprs.

From Rivest's documentation:

 <sexpr>    	:: <string> | <list>
 <string>   	:: <display>? <simple-string> ;
 <simple-string>	:: <raw> | <token> | <base-64> | <hexadecimal> | 
 		           <quoted-string> ;
 <display>  	:: "[" <simple-string> "]" ;
 <raw>      	:: <decimal> ":" <bytes> ;
 <decimal>  	:: <decimal-digit>+ ;
 		-- decimal numbers should have no unnecessary leading zeros
 <bytes> 	-- any string of bytes, of the indicated length
 <token>    	:: <tokenchar>+ ;
 <base-64>  	:: <decimal>? "|" ( <base-64-char> | <whitespace> )* "|" ;
 <hexadecimal>      :: "#" ( <hex-digit> | <white-space> )* "#" ;
 <quoted-string>    :: <decimal>? <quoted-string-body>  
 <quoted-string-body> :: "\"" <bytes> "\""
 <list>     	:: "(" ( <sexp> | <whitespace> )* ")" ;
 <whitespace> 	:: <whitespace-char>* ;
 <token-char>  	:: <alpha> | <decimal-digit> | <simple-punc> ;
 <alpha>       	:: <upper-case> | <lower-case> | <digit> ;
 <lower-case>  	:: "a" | ... | "z" ;
 <upper-case>  	:: "A" | ... | "Z" ;
 <decimal-digit>    :: "0" | ... | "9" ;
 <hex-digit>        :: <decimal-digit> | "A" | ... | "F" | "a" | ... | "f" ;
 <simple-punc> 	:: "-" | "." | "/" | "_" | ":" | "*" | "+" | "=" ;
 <whitespace-char>  :: " " | "\t" | "\r" | "\n" ;
 <base-64-char> 	:: <alpha> | <decimal-digit> | "+" | "/" | "=" ;
 <null>        	:: "" ;

Synopsis

Documentation

readSexprString :: String -> Sexpr StringSource

Read a Sexpr String in any encoding: Canonical, Basic, or Advanced.

readCanonicalSexprString :: String -> Sexpr StringSource

Read a Sexpr String in canonical encoding.

readSexpr :: Read a => String -> Sexpr aSource

Read a Sexpr a using the Read instance for a. The Sexpr may be in any encoding: Canonical, Basic, or Advanced.

sexpr :: Bool -> ReadP (Sexpr String)Source

Parser for Sexpr Strings suitable for embedding in other ReadP parsers.

canonicalSexpr :: ReadP (Sexpr String)Source

For some applications it is wise to accept only very carefully specified input. This is useful when you know you are receiving exactly a Canonical S-Expression. It will read only a Canonical S-expression (and optional terminating NUL), but not the Basic or Advanced encodings.