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