aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/language/problem.grammar
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/language/problem.grammar')
-rw-r--r--subprojects/frontend/src/language/problem.grammar149
1 files changed, 149 insertions, 0 deletions
diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar
new file mode 100644
index 00000000..1ace2872
--- /dev/null
+++ b/subprojects/frontend/src/language/problem.grammar
@@ -0,0 +1,149 @@
1@detectDelim
2
3@external prop implicitCompletion from '../../../../src/language/props.ts'
4
5@top Problem { statement* }
6
7statement {
8 ProblemDeclaration {
9 ckw<"problem"> QualifiedName "."
10 } |
11 ClassDefinition {
12 ckw<"abstract">? ckw<"class"> RelationName
13 (ckw<"extends"> sep<",", RelationName>)?
14 (ClassBody { "{" ReferenceDeclaration* "}" } | ".")
15 } |
16 EnumDefinition {
17 ckw<"enum"> RelationName
18 (EnumBody { "{" sep<",", IndividualNodeName> "}" } | ".")
19 } |
20 PredicateDefinition {
21 (ckw<"error"> ckw<"pred">? | ckw<"direct">? ckw<"pred">)
22 RelationName ParameterList<Parameter>?
23 PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." }
24 } |
25 RuleDefinition {
26 ckw<"direct">? ckw<"rule">
27 RuleName ParameterList<Parameter>?
28 RuleBody { ":" sep<OrOp, Conjunction> "~>" sep<OrOp, Action> "." }
29 } |
30 Assertion {
31 kw<"default">? (NotOp | UnknownOp)? RelationName
32 ParameterList<AssertionArgument> (":" LogicValue)? "."
33 } |
34 NodeValueAssertion {
35 IndividualNodeName ":" Constant "."
36 } |
37 IndividualDeclaration {
38 ckw<"indiv"> sep<",", IndividualNodeName> "."
39 } |
40 ScopeDeclaration {
41 kw<"scope"> sep<",", ScopeElement> "."
42 }
43}
44
45ReferenceDeclaration {
46 (kw<"refers"> | kw<"contains">)?
47 RelationName
48 RelationName
49 ( "[" Multiplicity? "]" )?
50 (kw<"opposite"> RelationName)?
51 ";"?
52}
53
54Parameter { RelationName? VariableName }
55
56Conjunction { ("," | Literal)+ }
57
58OrOp { ";" }
59
60Literal { NotOp? Atom (("=" | ":") sep1<"|", LogicValue>)? }
61
62Atom { RelationName "+"? ParameterList<Argument> }
63
64Action { ("," | ActionLiteral)+ }
65
66ActionLiteral {
67 ckw<"new"> VariableName |
68 ckw<"delete"> VariableName |
69 Literal
70}
71
72Argument { VariableName | Constant }
73
74AssertionArgument { NodeName | StarArgument | Constant }
75
76Constant { Real | String }
77
78LogicValue {
79 ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error">
80}
81
82ScopeElement { RelationName ("=" | "+=") Multiplicity }
83
84Multiplicity { (IntMult "..")? (IntMult | StarMult)}
85
86RelationName { QualifiedName }
87
88RuleName { QualifiedName }
89
90IndividualNodeName { QualifiedName }
91
92VariableName { QualifiedName }
93
94NodeName { QualifiedName }
95
96QualifiedName[implicitCompletion=true] { identifier ("::" identifier)* }
97
98kw<term> { @specialize[@name={term},implicitCompletion=true]<identifier, term> }
99
100ckw<term> { @extend[@name={term},implicitCompletion=true]<identifier, term> }
101
102ParameterList<content> { "(" sep<",", content> ")" }
103
104sep<separator, content> { sep1<separator, content>? }
105
106sep1<separator, content> { content (separator content)* }
107
108@skip { LineComment | BlockComment | whitespace }
109
110@tokens {
111 whitespace { std.whitespace+ }
112
113 LineComment { ("//" | "%") ![\n]* }
114
115 BlockComment { "/*" blockCommentRest }
116
117 blockCommentRest { ![*] blockCommentRest | "*" blockCommentAfterStar }
118
119 blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest }
120
121 @precedence { BlockComment, LineComment }
122
123 identifier { $[A-Za-z_] $[a-zA-Z0-9_]* }
124
125 int { $[0-9]+ }
126
127 IntMult { int }
128
129 StarMult { "*" }
130
131 Real { "-"? (exponential | int ("." (int | exponential))?) }
132
133 exponential { int ("e" | "E") ("+" | "-")? int }
134
135 String {
136 "'" (![\\'\n] | "\\" ![\n] | "\\\n")+ "'" |
137 "\"" (![\\"\n] | "\\" (![\n] | "\n"))* "\""
138 }
139
140 NotOp { "!" }
141
142 UnknownOp { "?" }
143
144 StarArgument { "*" }
145
146 "{" "}" "(" ")" "[" "]" "." ".." "," ":" "<->" "~>"
147}
148
149@detectDelim