-
Notifications
You must be signed in to change notification settings - Fork 0
/
Feather_ErrorStrategy.java
358 lines (332 loc) · 9.42 KB
/
Feather_ErrorStrategy.java
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
// import ANTLR's runtime libraries
import org.antlr.v4.runtime.*;
public class Feather_ErrorStrategy extends DefaultErrorStrategy
{
@Override
protected void reportNoViableAlternative(Parser parser, NoViableAltException e)
{
String errorInRule = e.getCtx().toStringTree(parser);
Token seen = e.getOffendingToken();
String errMsg = seen.getLine() + ": unexpected input '" + seen.getText() + "'" + getRuleExplanationInFeather(errorInRule);
parser.notifyErrorListeners(errMsg);
}
@Override
public void reportMissingToken(Parser parser)
{
String missing = getExpectedTokens(parser).toString(parser.getVocabulary());
Token seen = parser.getCurrentToken();
String errMsg = seen.getLine() + ": missing " + getTokenExplanationInFeather(missing, parser) + " before '" + seen.getText() + "'";
parser.notifyErrorListeners(errMsg);
}
@Override
public void reportUnwantedToken(Parser parser)
{
String expecting = getExpectedTokens(parser).toString(parser.getVocabulary());
Token seen = parser.getCurrentToken();
String errMsg = seen.getLine() + ": extranous input '" + seen.getText() + "', expecting " + getTokenExplanationInFeather(expecting, parser);
parser.notifyErrorListeners(errMsg);
}
@Override
public void reportInputMismatch(Parser parser, InputMismatchException e)
{
String errorInRule = e.getCtx().toStringTree(parser);
Token seen = parser.getCurrentToken();
String errMsg = seen.getLine() + ": unexpected input '" + seen.getText() + "'" + getRuleExplanationInFeather(errorInRule);
parser.notifyErrorListeners(errMsg);
}
private String getTokenExplanationInFeather(String token, Parser parser)
{
if ( token == null )
return "";
if ( token.equals("ATTRIBUTE_NAME") )
{
return "attribute name";
}
else if ( token.equals("FEATURE_VAR") )
{
return "feature variable";
}
else if ( token.equals("INTEGER_LITERAL") )
{
return "integer value";
}
else if ( token.equals("REAL_LITERAL") )
{
return "real value";
}
else if ( token.equals("STRING_LITERAL") )
{
String sCtx = parser.getContext().toString(parser);
sCtx = sCtx.replace("[", "");
sCtx = sCtx.replace("]", "");
String[] derivation = sCtx.split(" ");
if ( derivation == null || derivation.length == 0 )
return "";
if ( derivation[0].equals("assignedValue") ||
derivation[0].equals("attributeValue") ||
derivation[0].equals("stringOperand") )
{
return "string value";
}
else if ( derivation[0].equals("settingName") )
{
return "new feature name";
}
else if ( derivation[0].equals("featureName") )
{
return "feature name";
}
else if ( derivation[0].equals("parentName") )
{
return "parent feature's name";
}
}
return token;
}
private String getRuleExplanationInFeather(String rule)
{
if ( rule == null )
return "";
if ( rule.equals("declarations") )
{
return " in the declarations section";
}
else if ( rule.equals("featureDeclarations") )
{
return " in the feature declarations section";
}
else if ( rule.equals("rootFeature") )
{
return " in the root feature declaration";
}
else if ( rule.equals("featureDec") )
{
return " in the feature declaration";
}
else if ( rule.equals("decompRelDeclaration") )
{
return ", expecting a decomposition relation specification";
}
else if ( rule.equals("attributeDeclarations") )
{
return " in the attribute declarations section";
}
else if ( rule.equals("attributeDec") )
{
return " in the attribute declaration";
}
else if ( rule.equals("assignedValue") )
{
return ", expecting a value to be assigned to the attribute";
}
else if ( rule.equals("crossTreeConstraintDeclarations") )
{
return " in the cross-tree constraint declarations section";
}
else if ( rule.equals("crossTreeConstraintDec") )
{
return " in the cross-tree constraint declaration";
}
else if ( rule.equals("commands") )
{
return " in the commands section";
}
else if ( rule.equals("aCommand") )
{
return " in the command";
}
else if ( rule.equals("addFeature") )
{
return " in the feature addition command";
}
else if ( rule.equals("updateFeature") )
{
return " in the feature update command";
}
else if ( rule.equals("updateMultipleFeatures") )
{
return " in the multiple features update command";
}
else if ( rule.equals("removeFeature") )
{
return " in the feature removal command";
}
else if ( rule.equals("removeMultipleFeatures") )
{
return " in the multiple features removal command";
}
else if ( rule.equals("addConstraint") )
{
return " in the cross-tree constraint addition command";
}
else if ( rule.equals("updateConstraint") )
{
return " in the cross-tree constraint update command";
}
else if ( rule.equals("updateMultipleConstraints") )
{
return " in the multiple cross-tree constraints update command";
}
else if ( rule.equals("removeConstraint") )
{
return " in the cross-tree constraint removal command";
}
else if ( rule.equals("removeMultipleConstraints") )
{
return " in the multiple cross-tree constraints removal command";
}
else if ( rule.equals("featureDescription") )
{
return ", expecting a feature description";
}
else if ( rule.equals("featureNameDescription") )
{
return ", expecting a feature name description";
}
else if ( rule.equals("constraintDescription") )
{
return " in the cross-tree constraint description";
}
else if ( rule.equals("whereClause") )
{
return " in the where clause";
}
else if ( rule.equals("attributeList") )
{
return " in the attribute list section";
}
else if ( rule.equals("implicitAttributeAssignments") )
{
return " in the implicit attribute assignments section";
}
else if ( rule.equals("settingLocation") )
{
return ", expecting a feature location setting";
}
else if ( rule.equals("settingDecomposition") )
{
return ", expecting a feature decomposition relation setting";
}
else if ( rule.equals("otherAttributeDeclarations") )
{
return " in the attribute declarations section";
}
else if ( rule.equals("otherAttrDec") )
{
return " in the attribute declaration";
}
else if ( rule.equals("attributeValue") )
{
return ", expecting a value to be assigned to the attribute";
}
else if ( rule.equals("featureUpdates") )
{
return " in the update information section";
}
else if ( rule.equals("featUpdate") )
{
return ", expecting a feture property update";
}
else if ( rule.equals("settingName") )
{
return ", expecting a feature name setting";
}
else if ( rule.equals("limitedFeatureUpdates") )
{
return " in the update information section";
}
else if ( rule.equals("limitedFeatUpdate") )
{
return ", expecting a feture property update";
}
else if ( rule.equals("constraintUpdates") )
{
return " in the update information section";
}
else if ( rule.equals("constUpdate") )
{
return ", expecting a cross-tree constraint property update";
}
else if ( rule.equals("limitedConstraintUpdates") )
{
return " in the update information section";
}
else if ( rule.equals("decompRelValue") )
{
return ", expecting a decomposition relation value";
}
else if ( rule.equals("basicCrossTreeConstraint") )
{
return ", expecting a basic cross-tree constraint type";
}
else if ( rule.equals("arithmeticExpression") )
{
return ", expecting an arithmetic expression";
}
else if ( rule.equals("arithmeticOperand") )
{
return ", expecting an arithmetic expression operand";
}
else if ( rule.equals("highArithOp") )
{
return ", expecting an arithmetic operator";
}
else if ( rule.equals("lowArithOp") )
{
return ", expecting an arithmetic operator";
}
else if ( rule.equals("booleanExpression") )
{
return ", expecting a boolean expression";
}
else if ( rule.equals("booleanOperand") )
{
return ", expecting a boolean expression operand";
}
else if ( rule.equals("relOp") )
{
return ", expecting a relational operator";
}
else if ( rule.equals("stringEqualityCheck") )
{
return ", expecting a string equality check operation";
}
else if ( rule.equals("stringOperand") )
{
return ", expecting a string operand";
}
else if ( rule.equals("eqCheckOp") )
{
return ", expecting an equality check operator";
}
else if ( rule.equals("decompRelTypeCheck") )
{
return ", expecting a decomposition relation type equality check";
}
else if ( rule.equals("decompRelIDCheck") )
{
return ", expecting a decomposition relation ID equality check";
}
else if ( rule.equals("featureName") )
{
return ", expecting a feature name";
}
else if ( rule.equals("parentName") )
{
return ", expecting the parent feature's name";
}
else if ( rule.equals("attributeName") )
{
return ", expecting an attribute name";
}
else if ( rule.equals("featureVar") )
{
return ", expecting a feature variable";
}
else if ( rule.equals("bool_literal") )
{
return ", expecting a boolean literal";
}
return rule;
}
}