1 | package de.ugoe.cs.swe.bnftools.serializer; |
---|
2 | |
---|
3 | import com.google.inject.Inject; |
---|
4 | import com.google.inject.Provider; |
---|
5 | import de.ugoe.cs.swe.bnftools.ebnf.Atom; |
---|
6 | import de.ugoe.cs.swe.bnftools.ebnf.BnfEntry; |
---|
7 | import de.ugoe.cs.swe.bnftools.ebnf.Comment; |
---|
8 | import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList; |
---|
9 | import de.ugoe.cs.swe.bnftools.ebnf.DeltaEntry; |
---|
10 | import de.ugoe.cs.swe.bnftools.ebnf.EbnfPackage; |
---|
11 | import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf; |
---|
12 | import de.ugoe.cs.swe.bnftools.ebnf.ExtRule; |
---|
13 | import de.ugoe.cs.swe.bnftools.ebnf.GlobalCombinator; |
---|
14 | import de.ugoe.cs.swe.bnftools.ebnf.GroupedSequence; |
---|
15 | import de.ugoe.cs.swe.bnftools.ebnf.HookCombinator; |
---|
16 | import de.ugoe.cs.swe.bnftools.ebnf.Import; |
---|
17 | import de.ugoe.cs.swe.bnftools.ebnf.ImportSection; |
---|
18 | import de.ugoe.cs.swe.bnftools.ebnf.MergeEntry; |
---|
19 | import de.ugoe.cs.swe.bnftools.ebnf.OptionalSequence; |
---|
20 | import de.ugoe.cs.swe.bnftools.ebnf.RepeatRange; |
---|
21 | import de.ugoe.cs.swe.bnftools.ebnf.RepeatedSequence; |
---|
22 | import de.ugoe.cs.swe.bnftools.ebnf.Rule; |
---|
23 | import de.ugoe.cs.swe.bnftools.ebnf.RuleCombinator; |
---|
24 | import de.ugoe.cs.swe.bnftools.ebnf.RuleReference; |
---|
25 | import de.ugoe.cs.swe.bnftools.ebnf.SectionHeading; |
---|
26 | import de.ugoe.cs.swe.bnftools.ebnf.SingleDefinition; |
---|
27 | import de.ugoe.cs.swe.bnftools.ebnf.StringRule; |
---|
28 | import de.ugoe.cs.swe.bnftools.ebnf.Term; |
---|
29 | import de.ugoe.cs.swe.bnftools.services.EbnfGrammarAccess; |
---|
30 | import org.eclipse.emf.ecore.EObject; |
---|
31 | import org.eclipse.xtext.serializer.acceptor.ISemanticSequenceAcceptor; |
---|
32 | import org.eclipse.xtext.serializer.acceptor.SequenceFeeder; |
---|
33 | import org.eclipse.xtext.serializer.diagnostic.ISemanticSequencerDiagnosticProvider; |
---|
34 | import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor; |
---|
35 | import org.eclipse.xtext.serializer.sequencer.AbstractDelegatingSemanticSequencer; |
---|
36 | import org.eclipse.xtext.serializer.sequencer.GenericSequencer; |
---|
37 | import org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider; |
---|
38 | import org.eclipse.xtext.serializer.sequencer.ISemanticSequencer; |
---|
39 | import org.eclipse.xtext.serializer.sequencer.ITransientValueService; |
---|
40 | import org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient; |
---|
41 | |
---|
42 | @SuppressWarnings("all") |
---|
43 | public class EbnfSemanticSequencer extends AbstractDelegatingSemanticSequencer { |
---|
44 | |
---|
45 | @Inject |
---|
46 | private EbnfGrammarAccess grammarAccess; |
---|
47 | |
---|
48 | public void createSequence(EObject context, EObject semanticObject) { |
---|
49 | if(semanticObject.eClass().getEPackage() == EbnfPackage.eINSTANCE) switch(semanticObject.eClass().getClassifierID()) { |
---|
50 | case EbnfPackage.ATOM: |
---|
51 | if(context == grammarAccess.getAtomRule()) { |
---|
52 | sequence_Atom(context, (Atom) semanticObject); |
---|
53 | return; |
---|
54 | } |
---|
55 | else break; |
---|
56 | case EbnfPackage.BNF_ENTRY: |
---|
57 | if(context == grammarAccess.getBnfEntryRule()) { |
---|
58 | sequence_BnfEntry(context, (BnfEntry) semanticObject); |
---|
59 | return; |
---|
60 | } |
---|
61 | else break; |
---|
62 | case EbnfPackage.COMMENT: |
---|
63 | if(context == grammarAccess.getCommentRule()) { |
---|
64 | sequence_Comment(context, (Comment) semanticObject); |
---|
65 | return; |
---|
66 | } |
---|
67 | else break; |
---|
68 | case EbnfPackage.DEFINITION_LIST: |
---|
69 | if(context == grammarAccess.getDefinitionListRule()) { |
---|
70 | sequence_DefinitionList(context, (DefinitionList) semanticObject); |
---|
71 | return; |
---|
72 | } |
---|
73 | else break; |
---|
74 | case EbnfPackage.DELTA_ENTRY: |
---|
75 | if(context == grammarAccess.getDeltaEntryRule()) { |
---|
76 | sequence_DeltaEntry(context, (DeltaEntry) semanticObject); |
---|
77 | return; |
---|
78 | } |
---|
79 | else break; |
---|
80 | case EbnfPackage.ETSI_BNF: |
---|
81 | if(context == grammarAccess.getEtsiBnfRule()) { |
---|
82 | sequence_EtsiBnf(context, (EtsiBnf) semanticObject); |
---|
83 | return; |
---|
84 | } |
---|
85 | else break; |
---|
86 | case EbnfPackage.EXT_RULE: |
---|
87 | if(context == grammarAccess.getExtRuleRule()) { |
---|
88 | sequence_ExtRule(context, (ExtRule) semanticObject); |
---|
89 | return; |
---|
90 | } |
---|
91 | else break; |
---|
92 | case EbnfPackage.GLOBAL_COMBINATOR: |
---|
93 | if(context == grammarAccess.getGlobalCombinatorRule() || |
---|
94 | context == grammarAccess.getMergeRuleRule()) { |
---|
95 | sequence_GlobalCombinator(context, (GlobalCombinator) semanticObject); |
---|
96 | return; |
---|
97 | } |
---|
98 | else break; |
---|
99 | case EbnfPackage.GROUPED_SEQUENCE: |
---|
100 | if(context == grammarAccess.getGroupedSequenceRule()) { |
---|
101 | sequence_GroupedSequence(context, (GroupedSequence) semanticObject); |
---|
102 | return; |
---|
103 | } |
---|
104 | else break; |
---|
105 | case EbnfPackage.HOOK_COMBINATOR: |
---|
106 | if(context == grammarAccess.getHookCombinatorRule() || |
---|
107 | context == grammarAccess.getMergeRuleRule()) { |
---|
108 | sequence_HookCombinator(context, (HookCombinator) semanticObject); |
---|
109 | return; |
---|
110 | } |
---|
111 | else break; |
---|
112 | case EbnfPackage.IMPORT: |
---|
113 | if(context == grammarAccess.getImportRule()) { |
---|
114 | sequence_Import(context, (Import) semanticObject); |
---|
115 | return; |
---|
116 | } |
---|
117 | else break; |
---|
118 | case EbnfPackage.IMPORT_SECTION: |
---|
119 | if(context == grammarAccess.getImportSectionRule()) { |
---|
120 | sequence_ImportSection(context, (ImportSection) semanticObject); |
---|
121 | return; |
---|
122 | } |
---|
123 | else break; |
---|
124 | case EbnfPackage.MERGE_ENTRY: |
---|
125 | if(context == grammarAccess.getMergeEntryRule()) { |
---|
126 | sequence_MergeEntry(context, (MergeEntry) semanticObject); |
---|
127 | return; |
---|
128 | } |
---|
129 | else break; |
---|
130 | case EbnfPackage.OPTIONAL_SEQUENCE: |
---|
131 | if(context == grammarAccess.getOptionalSequenceRule()) { |
---|
132 | sequence_OptionalSequence(context, (OptionalSequence) semanticObject); |
---|
133 | return; |
---|
134 | } |
---|
135 | else break; |
---|
136 | case EbnfPackage.REPEAT_RANGE: |
---|
137 | if(context == grammarAccess.getRepeatRangeRule()) { |
---|
138 | sequence_RepeatRange(context, (RepeatRange) semanticObject); |
---|
139 | return; |
---|
140 | } |
---|
141 | else break; |
---|
142 | case EbnfPackage.REPEATED_SEQUENCE: |
---|
143 | if(context == grammarAccess.getRepeatedSequenceRule()) { |
---|
144 | sequence_RepeatedSequence(context, (RepeatedSequence) semanticObject); |
---|
145 | return; |
---|
146 | } |
---|
147 | else break; |
---|
148 | case EbnfPackage.RULE: |
---|
149 | if(context == grammarAccess.getRuleRule()) { |
---|
150 | sequence_Rule(context, (Rule) semanticObject); |
---|
151 | return; |
---|
152 | } |
---|
153 | else break; |
---|
154 | case EbnfPackage.RULE_COMBINATOR: |
---|
155 | if(context == grammarAccess.getMergeRuleRule() || |
---|
156 | context == grammarAccess.getRuleCombinatorRule()) { |
---|
157 | sequence_RuleCombinator(context, (RuleCombinator) semanticObject); |
---|
158 | return; |
---|
159 | } |
---|
160 | else break; |
---|
161 | case EbnfPackage.RULE_REFERENCE: |
---|
162 | if(context == grammarAccess.getRuleReferenceRule()) { |
---|
163 | sequence_RuleReference(context, (RuleReference) semanticObject); |
---|
164 | return; |
---|
165 | } |
---|
166 | else break; |
---|
167 | case EbnfPackage.SECTION_HEADING: |
---|
168 | if(context == grammarAccess.getSectionHeadingRule()) { |
---|
169 | sequence_SectionHeading(context, (SectionHeading) semanticObject); |
---|
170 | return; |
---|
171 | } |
---|
172 | else break; |
---|
173 | case EbnfPackage.SINGLE_DEFINITION: |
---|
174 | if(context == grammarAccess.getSingleDefinitionRule()) { |
---|
175 | sequence_SingleDefinition(context, (SingleDefinition) semanticObject); |
---|
176 | return; |
---|
177 | } |
---|
178 | else break; |
---|
179 | case EbnfPackage.STRING_RULE: |
---|
180 | if(context == grammarAccess.getStringRuleRule()) { |
---|
181 | sequence_StringRule(context, (StringRule) semanticObject); |
---|
182 | return; |
---|
183 | } |
---|
184 | else break; |
---|
185 | case EbnfPackage.TERM: |
---|
186 | if(context == grammarAccess.getTermRule()) { |
---|
187 | sequence_Term(context, (Term) semanticObject); |
---|
188 | return; |
---|
189 | } |
---|
190 | else break; |
---|
191 | } |
---|
192 | if (errorAcceptor != null) errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context)); |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * Constraint: |
---|
197 | * (atomStringRule=StringRule | atomRuleReference=RuleReference) |
---|
198 | */ |
---|
199 | protected void sequence_Atom(EObject context, Atom semanticObject) { |
---|
200 | genericSequencer.createSequence(context, semanticObject); |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | /** |
---|
205 | * Constraint: |
---|
206 | * (sectionheader=SectionHeading | rule=Rule | comment=Comment) |
---|
207 | */ |
---|
208 | protected void sequence_BnfEntry(EObject context, BnfEntry semanticObject) { |
---|
209 | genericSequencer.createSequence(context, semanticObject); |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | /** |
---|
214 | * Constraint: |
---|
215 | * content=ML_COMMENT |
---|
216 | */ |
---|
217 | protected void sequence_Comment(EObject context, Comment semanticObject) { |
---|
218 | if(errorAcceptor != null) { |
---|
219 | if(transientValues.isValueTransient(semanticObject, EbnfPackage.Literals.COMMENT__CONTENT) == ValueTransient.YES) |
---|
220 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, EbnfPackage.Literals.COMMENT__CONTENT)); |
---|
221 | } |
---|
222 | INodesForEObjectProvider nodes = createNodeProvider(semanticObject); |
---|
223 | SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes); |
---|
224 | feeder.accept(grammarAccess.getCommentAccess().getContentML_COMMENTTerminalRuleCall_1_0(), semanticObject.getContent()); |
---|
225 | feeder.finish(); |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | /** |
---|
230 | * Constraint: |
---|
231 | * (singleDefinition+=SingleDefinition singleDefinition+=SingleDefinition*) |
---|
232 | */ |
---|
233 | protected void sequence_DefinitionList(EObject context, DefinitionList semanticObject) { |
---|
234 | genericSequencer.createSequence(context, semanticObject); |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | /** |
---|
239 | * Constraint: |
---|
240 | * (rule=Rule | sectionheader=SectionHeading | extRule=ExtRule) |
---|
241 | */ |
---|
242 | protected void sequence_DeltaEntry(EObject context, DeltaEntry semanticObject) { |
---|
243 | genericSequencer.createSequence(context, semanticObject); |
---|
244 | } |
---|
245 | |
---|
246 | |
---|
247 | /** |
---|
248 | * Constraint: |
---|
249 | * ( |
---|
250 | * (name=ID type='/bnf'? importSection=ImportSection? bnfEntry+=BnfEntry+) | |
---|
251 | * (type='/delta' importSection=ImportSection? deltaEntry+=DeltaEntry*) | |
---|
252 | * (type='/merge' importSection=ImportSection? mergeEntry+=MergeEntry*) |
---|
253 | * ) |
---|
254 | */ |
---|
255 | protected void sequence_EtsiBnf(EObject context, EtsiBnf semanticObject) { |
---|
256 | genericSequencer.createSequence(context, semanticObject); |
---|
257 | } |
---|
258 | |
---|
259 | |
---|
260 | /** |
---|
261 | * Constraint: |
---|
262 | * ((rulenumber=INT rulevariant=ID?)? name=ID ruleext=INT elements+=Atom*) |
---|
263 | */ |
---|
264 | protected void sequence_ExtRule(EObject context, ExtRule semanticObject) { |
---|
265 | genericSequencer.createSequence(context, semanticObject); |
---|
266 | } |
---|
267 | |
---|
268 | |
---|
269 | /** |
---|
270 | * Constraint: |
---|
271 | * logic=LOGIC |
---|
272 | */ |
---|
273 | protected void sequence_GlobalCombinator(EObject context, GlobalCombinator semanticObject) { |
---|
274 | if(errorAcceptor != null) { |
---|
275 | if(transientValues.isValueTransient(semanticObject, EbnfPackage.Literals.MERGE_RULE__LOGIC) == ValueTransient.YES) |
---|
276 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, EbnfPackage.Literals.MERGE_RULE__LOGIC)); |
---|
277 | } |
---|
278 | INodesForEObjectProvider nodes = createNodeProvider(semanticObject); |
---|
279 | SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes); |
---|
280 | feeder.accept(grammarAccess.getGlobalCombinatorAccess().getLogicLOGICTerminalRuleCall_1_0(), semanticObject.getLogic()); |
---|
281 | feeder.finish(); |
---|
282 | } |
---|
283 | |
---|
284 | |
---|
285 | /** |
---|
286 | * Constraint: |
---|
287 | * definitionList+=DefinitionList |
---|
288 | */ |
---|
289 | protected void sequence_GroupedSequence(EObject context, GroupedSequence semanticObject) { |
---|
290 | genericSequencer.createSequence(context, semanticObject); |
---|
291 | } |
---|
292 | |
---|
293 | |
---|
294 | /** |
---|
295 | * Constraint: |
---|
296 | * (name=ID ruleext=INT logic=LOGIC? LABEL+=STRING+) |
---|
297 | */ |
---|
298 | protected void sequence_HookCombinator(EObject context, HookCombinator semanticObject) { |
---|
299 | genericSequencer.createSequence(context, semanticObject); |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | /** |
---|
304 | * Constraint: |
---|
305 | * imports+=Import+ |
---|
306 | */ |
---|
307 | protected void sequence_ImportSection(EObject context, ImportSection semanticObject) { |
---|
308 | genericSequencer.createSequence(context, semanticObject); |
---|
309 | } |
---|
310 | |
---|
311 | |
---|
312 | /** |
---|
313 | * Constraint: |
---|
314 | * (importURI=STRING (grammarType='core' | grammarType='package' | grammarType='update')? label=ID?) |
---|
315 | */ |
---|
316 | protected void sequence_Import(EObject context, Import semanticObject) { |
---|
317 | genericSequencer.createSequence(context, semanticObject); |
---|
318 | } |
---|
319 | |
---|
320 | |
---|
321 | /** |
---|
322 | * Constraint: |
---|
323 | * (sectionheader=SectionHeading | mergeRule=MergeRule) |
---|
324 | */ |
---|
325 | protected void sequence_MergeEntry(EObject context, MergeEntry semanticObject) { |
---|
326 | genericSequencer.createSequence(context, semanticObject); |
---|
327 | } |
---|
328 | |
---|
329 | |
---|
330 | /** |
---|
331 | * Constraint: |
---|
332 | * definitionList+=DefinitionList |
---|
333 | */ |
---|
334 | protected void sequence_OptionalSequence(EObject context, OptionalSequence semanticObject) { |
---|
335 | genericSequencer.createSequence(context, semanticObject); |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | /** |
---|
340 | * Constraint: |
---|
341 | * (from=INT to=INT) |
---|
342 | */ |
---|
343 | protected void sequence_RepeatRange(EObject context, RepeatRange semanticObject) { |
---|
344 | if(errorAcceptor != null) { |
---|
345 | if(transientValues.isValueTransient(semanticObject, EbnfPackage.Literals.REPEAT_RANGE__FROM) == ValueTransient.YES) |
---|
346 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, EbnfPackage.Literals.REPEAT_RANGE__FROM)); |
---|
347 | if(transientValues.isValueTransient(semanticObject, EbnfPackage.Literals.REPEAT_RANGE__TO) == ValueTransient.YES) |
---|
348 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, EbnfPackage.Literals.REPEAT_RANGE__TO)); |
---|
349 | } |
---|
350 | INodesForEObjectProvider nodes = createNodeProvider(semanticObject); |
---|
351 | SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes); |
---|
352 | feeder.accept(grammarAccess.getRepeatRangeAccess().getFromINTTerminalRuleCall_2_0(), semanticObject.getFrom()); |
---|
353 | feeder.accept(grammarAccess.getRepeatRangeAccess().getToINTTerminalRuleCall_4_0(), semanticObject.getTo()); |
---|
354 | feeder.finish(); |
---|
355 | } |
---|
356 | |
---|
357 | |
---|
358 | /** |
---|
359 | * Constraint: |
---|
360 | * (definitions+=DefinitionList (morethanonce?='+'? | range=RepeatRange?)) |
---|
361 | */ |
---|
362 | protected void sequence_RepeatedSequence(EObject context, RepeatedSequence semanticObject) { |
---|
363 | genericSequencer.createSequence(context, semanticObject); |
---|
364 | } |
---|
365 | |
---|
366 | |
---|
367 | /** |
---|
368 | * Constraint: |
---|
369 | * (name=ID logic=LOGIC LABEL+=STRING*) |
---|
370 | */ |
---|
371 | protected void sequence_RuleCombinator(EObject context, RuleCombinator semanticObject) { |
---|
372 | genericSequencer.createSequence(context, semanticObject); |
---|
373 | } |
---|
374 | |
---|
375 | |
---|
376 | /** |
---|
377 | * Constraint: |
---|
378 | * ruleref=[Rule|ID] |
---|
379 | */ |
---|
380 | protected void sequence_RuleReference(EObject context, RuleReference semanticObject) { |
---|
381 | if(errorAcceptor != null) { |
---|
382 | if(transientValues.isValueTransient(semanticObject, EbnfPackage.Literals.RULE_REFERENCE__RULEREF) == ValueTransient.YES) |
---|
383 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, EbnfPackage.Literals.RULE_REFERENCE__RULEREF)); |
---|
384 | } |
---|
385 | INodesForEObjectProvider nodes = createNodeProvider(semanticObject); |
---|
386 | SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes); |
---|
387 | feeder.accept(grammarAccess.getRuleReferenceAccess().getRulerefRuleIDTerminalRuleCall_0_1(), semanticObject.getRuleref()); |
---|
388 | feeder.finish(); |
---|
389 | } |
---|
390 | |
---|
391 | |
---|
392 | /** |
---|
393 | * Constraint: |
---|
394 | * ((rulenumber=INT rulevariant=ID?)? name=ID definitionList=DefinitionList?) |
---|
395 | */ |
---|
396 | protected void sequence_Rule(EObject context, Rule semanticObject) { |
---|
397 | genericSequencer.createSequence(context, semanticObject); |
---|
398 | } |
---|
399 | |
---|
400 | |
---|
401 | /** |
---|
402 | * Constraint: |
---|
403 | * sectionHeader=SECTIONHEADER |
---|
404 | */ |
---|
405 | protected void sequence_SectionHeading(EObject context, SectionHeading semanticObject) { |
---|
406 | if(errorAcceptor != null) { |
---|
407 | if(transientValues.isValueTransient(semanticObject, EbnfPackage.Literals.SECTION_HEADING__SECTION_HEADER) == ValueTransient.YES) |
---|
408 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, EbnfPackage.Literals.SECTION_HEADING__SECTION_HEADER)); |
---|
409 | } |
---|
410 | INodesForEObjectProvider nodes = createNodeProvider(semanticObject); |
---|
411 | SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes); |
---|
412 | feeder.accept(grammarAccess.getSectionHeadingAccess().getSectionHeaderSECTIONHEADERTerminalRuleCall_1_0(), semanticObject.getSectionHeader()); |
---|
413 | feeder.finish(); |
---|
414 | } |
---|
415 | |
---|
416 | |
---|
417 | /** |
---|
418 | * Constraint: |
---|
419 | * terms+=Term+ |
---|
420 | */ |
---|
421 | protected void sequence_SingleDefinition(EObject context, SingleDefinition semanticObject) { |
---|
422 | genericSequencer.createSequence(context, semanticObject); |
---|
423 | } |
---|
424 | |
---|
425 | |
---|
426 | /** |
---|
427 | * Constraint: |
---|
428 | * (literal=STRING | colon=COLON) |
---|
429 | */ |
---|
430 | protected void sequence_StringRule(EObject context, StringRule semanticObject) { |
---|
431 | genericSequencer.createSequence(context, semanticObject); |
---|
432 | } |
---|
433 | |
---|
434 | |
---|
435 | /** |
---|
436 | * Constraint: |
---|
437 | * (termAtom=Atom | termGroupedSequence=GroupedSequence | termOptionalSequence=OptionalSequence | termRepeatedSequence=RepeatedSequence) |
---|
438 | */ |
---|
439 | protected void sequence_Term(EObject context, Term semanticObject) { |
---|
440 | genericSequencer.createSequence(context, semanticObject); |
---|
441 | } |
---|
442 | } |
---|