aboutsummaryrefslogtreecommitdiff
path: root/sucl/rule.dcl
blob: 6f61f4c9863408f1e1e8d1b769989ee3c63c9946 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
definition module rule

// $Id$

from graph import Graph,Node
from StdOverloaded import ==,toString
from StdFile import <<<
from cleanversion import String
from StdClass import Eq

// --- Exported types

:: Rule sym var
:: Rgraph sym var

// --- Functions on rules

// Build a rule from its constituents
mkrule    :: .[var] var (Graph sym var) -> .Rule sym var

// The arguments of a rule, i.e. the roots of its lhs
arguments :: !.(Rule sym var) -> [var]

// The root of a rule, i.e. of its rhs
ruleroot  :: !.(Rule sym var) -> var

// The graph part of a rule, i.e. its bindings
rulegraph :: !.(Rule sym var) -> Graph sym var

instance toString (Rule sym var) | toString sym & toString var & == var
ruleToString :: (sym->.String) .(Rule sym var) -> String | Eq,toString var

showrule ::
    (sym->String)
    (var->String)
    (Rule sym var)
 -> String
 |  == var

showruleanch ::
    (sym->String)
    (var->String)
    [Bool]
    (Rule sym var)
    [var]
 -> String
 |  == var

// --- Functions on rooted graphs

// The empty rooted graph with a given root
emptyrgraph  :: var -> .Rgraph sym var

// Update the contents of a variable in a rooted graph
updatergraph :: var .(Node sym var) !.(Rgraph sym var) -> .Rgraph sym var

// Prune a rooted graph at a variable (making it free)
prunergraph  :: var !.(Rgraph sym var) -> .Rgraph sym var

// Get the root of a rooted graph
rgraphroot   :: !.(Rgraph sym var) -> var

// Get the graph part of a rooted graph
rgraphgraph  :: !.(Rgraph sym var) -> Graph sym var

// Build a rooted graph from a root and a graph
mkrgraph     :: var (Graph sym var) -> .Rgraph sym var

instance == (Rgraph sym var) | == sym & == var
instance toString (Rgraph sym var) | toString sym & toString var & Eq var

showrgraph ::
    (sym->String)
    (var->String)
    (Rgraph sym var)
 -> String
 |  == var

instance <<< (Rgraph sym var) | toString sym & toString var & == var
instance <<< (Rule sym var) | toString sym & toString,== var

(writergraph) infixl :: *File .(Rgraph sym var) -> .File | toString sym & ==,toString var
(writerule) infixl :: *File .(Rule sym var) -> .File | toString sym & ==,toString var