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