This module defines the basic data structures for representing graphs and hypergraphs and the corresponding graph parsers.
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.
getSemRep
:: (a, [(b, [Int])]) -> a
Access the semantic representation of the result of a graph parser.
pSucceed
:: a -> [(b, [Int])] -> (a, [(b, [Int])])
Given an arbitrary value v
, pSucceed
always succeeds
returning v
as a result without any consumption of the input graph g
.
eoi
:: [(a, [Int])] -> ((), [(a, [Int])])
eoi
succeeds only if the graph is already completely consumed.
In this case, the result ()
is returned
edge
:: Data a => (a, [Int]) -> [(a, [Int])] -> ((), [(a, [Int])])
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])])
The choice between two parsers.
(<*>)
:: ([(a, [Int])] -> (b -> c, [(a, [Int])])) -> ([(a, [Int])] -> (b, [(a, [Int])])) -> [(a, [Int])] -> (c, [(a, [Int])])
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])])
(<$)
:: a -> ([(b, [Int])] -> (c, [(b, [Int])])) -> [(b, [Int])] -> (a, [(b, [Int])])
(<*)
:: ([(a, [Int])] -> (b, [(a, [Int])])) -> ([(a, [Int])] -> (c, [(a, [Int])])) -> [(a, [Int])] -> (b, [(a, [Int])])
(*>)
:: ([(a, [Int])] -> (b, [(a, [Int])])) -> ([(a, [Int])] -> (c, [(a, [Int])])) -> [(a, [Int])] -> (c, [(a, [Int])])
chain
:: ((Int, Int) -> [(a, [Int])] -> (b, [(a, [Int])])) -> (Int, Int) -> [(a, [Int])] -> ([b], [(a, [Int])])
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
.