Module Parser

Author
Michael Hanus
Version
November 2020

Library with functional logic parser combinators.

Adapted from: Rafael Caballero and Francisco J. Lopez-Fraguas: A Functional Logic Perspective of Parsing. In Proc. FLOPS'99, Springer LNCS 1722, pp. 85-99, 1999

Exported Datatypes:

Exported Datatypes


type Parser token = [token] -> [token]
type ParserRep rep token = rep -> Parser token

Exported Functions


(<|>) :: ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]  Non-deterministic 

Combines two parsers without representation in an alternative manner.

Further infos:
  • defined as right-associative infix operator with precedence 2

(<||>) :: (a -> [b] -> [b]) -> (a -> [b] -> [b]) -> a -> [b] -> [b]  Non-deterministic 

Combines two parsers with representation in an alternative manner.

Further infos:
  • defined as right-associative infix operator with precedence 2

(<*>) :: Data a => ([a] -> [a]) -> ([a] -> [a]) -> [a] -> [a]  Non-deterministic 

Combines two parsers (with or without representation) in a sequential manner.

Further infos:
  • defined as right-associative infix operator with precedence 4

(>>>) :: (Data a, Data b) => ([a] -> [a]) -> b -> b -> [a] -> [a]  Non-deterministic 

Attaches a representation to a parser without representation.

Further infos:
  • defined as right-associative infix operator with precedence 3

empty :: [a] -> [a]  Deterministic 

The empty parser which recognizes the empty word.

Further infos:
  • solution complete, i.e., able to compute all solutions

terminal :: Data a => a -> [a] -> [a]  Deterministic 

A parser recognizing a particular terminal symbol.

Further infos:
  • partially defined

satisfy :: Data a => (a -> Bool) -> a -> [a] -> [a]  Non-deterministic 

A parser (with representation) recognizing a terminal satisfying a given predicate.

Further infos:
  • partially defined

star :: (Data b, Data a) => (a -> [b] -> [b]) -> [a] -> [b] -> [b]  Non-deterministic 

A star combinator for parsers. The returned parser repeats zero or more times a parser p with representation and returns the representation of all parsers in a list.


some :: (Data b, Data a) => (a -> [b] -> [b]) -> [a] -> [b] -> [b]  Non-deterministic 

A some combinator for parsers. The returned parser repeats the argument parser (with representation) at least once.