Module Grappa

This module defines the basic data structures for representing graphs and hypergraphs and the corresponding graph parsers.

Exported Datatypes:

Exported Datatypes


type Node = Int

All nodes are numbered.


type Edge t = (t, [Node])

A type for the edge labels t can be passed as a type parameter. In the simplest case this can be just strings representing their labels. The tentacle numbers correspond to the position of a node in the list of incident nodes.


type Graph t = [Edge t]

A graph is declared as a list of edges each with its incident nodes


type Grappa t res = Graph t -> (res, Graph t)

The type of a graph parser. It is parameterized over the type res of semantic values associated to graphs.


Exported Functions


getSemRep :: (a, [(b, [Int])]) -> a  Deterministic 

Access the semantic representation of the result of a graph parser.

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

pSucceed :: a -> [(b, [Int])] -> (a, [(b, [Int])])  Deterministic 

Given an arbitrary value v, pSucceed always succeeds returning v as a result without any consumption of the input graph g.

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

eoi :: [(a, [Int])] -> ((), [(a, [Int])])  Deterministic 

eoi succeeds only if the graph is already completely consumed. In this case, the result () is returned

Further infos:
  • partially defined

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

The parser edge e succeeds only if the given edge e is part of the given input graph g.


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

The choice between two parsers.


(<*>) :: ([(a, [Int])] -> (b -> c, [(a, [Int])])) -> ([(a, [Int])] -> (b, [(a, [Int])])) -> [(a, [Int])] -> (c, [(a, [Int])])  Deterministic 

The successive application of two parsers where the result is constructed by function application.


(<$>) :: (a -> b) -> ([(c, [Int])] -> (a, [(c, [Int])])) -> [(c, [Int])] -> (b, [(c, [Int])])  Deterministic 


(<$) :: a -> ([(b, [Int])] -> (c, [(b, [Int])])) -> [(b, [Int])] -> (a, [(b, [Int])])  Deterministic 


(<*) :: ([(a, [Int])] -> (b, [(a, [Int])])) -> ([(a, [Int])] -> (c, [(a, [Int])])) -> [(a, [Int])] -> (b, [(a, [Int])])  Deterministic 


(*>) :: ([(a, [Int])] -> (b, [(a, [Int])])) -> ([(a, [Int])] -> (c, [(a, [Int])])) -> [(a, [Int])] -> (c, [(a, [Int])])  Deterministic 


chain :: ((Int, Int) -> [(a, [Int])] -> (b, [(a, [Int])])) -> (Int, Int) -> [(a, [Int])] -> ([b], [(a, [Int])])  Non-deterministic 

The combinator chain p (n1,n2) can be used to identify a non-empty chain of graphs that can be parsed with p. This chain has to be anchored between the nodes n1 and n2.