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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
@top Problem { statement* }
statement {
ProblemDeclaration {
ckw<"problem"> QualifiedName "."
} |
ClassDefinition {
ckw<"abstract">? ckw<"class"> RelationName
(ckw<"extends"> sep<",", RelationName>)?
(ClassBody { "{" ReferenceDeclaration* "}" } | ".")
} |
EnumDefinition {
ckw<"enum"> RelationName
(EnumBody { "{" sep<",", UniqueNodeName> "}" } | ".")
} |
PredicateDefinition {
(ckw<"error"> ckw<"pred">? | ckw<"direct">? ckw<"pred">)
RelationName ParameterList<Parameter>?
PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." }
} |
RuleDefinition {
ckw<"direct">? ckw<"rule">
RuleName ParameterList<Parameter>?
RuleBody { ":" sep<OrOp, Conjunction> "~>" sep<OrOp, Action> "." }
} |
Assertion {
ckw<"default">? (NotOp | UnknownOp)? RelationName
ParameterList<AssertionArgument> (":" LogicValue)? "."
} |
NodeValueAssertion {
UniqueNodeName ":" Constant "."
} |
UniqueDeclaration {
ckw<"unique"> sep<",", UniqueNodeName> "."
} |
ScopeDeclaration {
ckw<"scope"> sep<",", ScopeElement> "."
}
}
ReferenceDeclaration {
(kw<"refers"> | kw<"contains">)?
RelationName
RelationName
( "[" Multiplicity? "]" )?
(kw<"opposite"> RelationName)?
";"?
}
Parameter { RelationName? VariableName }
Conjunction { ("," | Literal)+ }
OrOp { ";" }
Literal { NotOp? Atom (("=" | ":") sep1<"|", LogicValue>)? }
Atom { RelationName "+"? ParameterList<Argument> }
Action { ("," | ActionLiteral)+ }
ActionLiteral {
ckw<"new"> VariableName |
ckw<"delete"> VariableName |
Literal
}
Argument { VariableName | Constant }
AssertionArgument { NodeName | StarArgument | Constant }
Constant { Real | String }
LogicValue {
ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error">
}
ScopeElement { RelationName ("=" | "+=") Multiplicity }
Multiplicity { (IntMult "..")? (IntMult | StarMult)}
RelationName { QualifiedName }
RuleName { QualifiedName }
UniqueNodeName { QualifiedName }
VariableName { QualifiedName }
NodeName { QualifiedName }
QualifiedName { identifier ("::" identifier)* }
kw<term> { @specialize[@name={term}]<identifier, term> }
ckw<term> { @extend[@name={term}]<identifier, term> }
ParameterList<content> { "(" sep<",", content> ")" }
sep<separator, content> { sep1<separator, content>? }
sep1<separator, content> { content (separator content)* }
@skip { LineComment | BlockComment | whitespace }
@tokens {
whitespace { std.whitespace+ }
LineComment { ("//" | "%") ![\n]* }
BlockComment { "/*" blockCommentRest }
blockCommentRest { ![*] blockCommentRest | "*" blockCommentAfterStar }
blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest }
@precedence { BlockComment, LineComment }
identifier { $[A-Za-z_] $[a-zA-Z0-9_]* }
int { $[0-9]+ }
IntMult { int }
StarMult { "*" }
Real { "-"? (exponential | int ("." (int | exponential))?) }
exponential { int ("e" | "E") ("+" | "-")? int }
String {
"'" (![\\'\n] | "\\" ![\n] | "\\\n")+ "'" |
"\"" (![\\"\n] | "\\" (![\n] | "\n"))* "\""
}
NotOp { "!" }
UnknownOp { "?" }
StarArgument { "*" }
"{" "}" "(" ")" "[" "]" "." ".." "," ":" "<->" "~>"
}
@detectDelim
|