1 | /**
|
---|
2 | * generated by Xtext
|
---|
3 | */
|
---|
4 | package de.ugoe.cs.swe.bnftools.generator;
|
---|
5 |
|
---|
6 | import com.google.common.base.Objects;
|
---|
7 | import com.google.common.collect.Iterables;
|
---|
8 | import de.ugoe.cs.swe.bnftools.ebnf.Atom;
|
---|
9 | import de.ugoe.cs.swe.bnftools.ebnf.BnfEntry;
|
---|
10 | import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList;
|
---|
11 | import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf;
|
---|
12 | import de.ugoe.cs.swe.bnftools.ebnf.GroupedSequence;
|
---|
13 | import de.ugoe.cs.swe.bnftools.ebnf.OptionalSequence;
|
---|
14 | import de.ugoe.cs.swe.bnftools.ebnf.RepeatedSequence;
|
---|
15 | import de.ugoe.cs.swe.bnftools.ebnf.Rule;
|
---|
16 | import de.ugoe.cs.swe.bnftools.ebnf.RuleReference;
|
---|
17 | import de.ugoe.cs.swe.bnftools.ebnf.SingleDefinition;
|
---|
18 | import de.ugoe.cs.swe.bnftools.ebnf.StringRule;
|
---|
19 | import de.ugoe.cs.swe.bnftools.ebnf.Term;
|
---|
20 | import org.eclipse.emf.common.util.EList;
|
---|
21 | import org.eclipse.emf.common.util.TreeIterator;
|
---|
22 | import org.eclipse.emf.ecore.EObject;
|
---|
23 | import org.eclipse.emf.ecore.resource.Resource;
|
---|
24 | import org.eclipse.xtend2.lib.StringConcatenation;
|
---|
25 | import org.eclipse.xtext.generator.IFileSystemAccess;
|
---|
26 | import org.eclipse.xtext.generator.IGenerator;
|
---|
27 | import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
---|
28 | import org.eclipse.xtext.xbase.lib.IteratorExtensions;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Generates code from your model files on save.
|
---|
32 | *
|
---|
33 | * see http://www.eclipse.org/Xtext/documentation.html#TutorialCodeGeneration
|
---|
34 | */
|
---|
35 | @SuppressWarnings("all")
|
---|
36 | public class EbnfGenerator implements IGenerator {
|
---|
37 | public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
|
---|
38 | TreeIterator<EObject> _allContents = resource.getAllContents();
|
---|
39 | Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_allContents);
|
---|
40 | Iterable<EtsiBnf> _filter = Iterables.<EtsiBnf>filter(_iterable, EtsiBnf.class);
|
---|
41 | for (final EtsiBnf e : _filter) {
|
---|
42 | EList<BnfEntry> _bnfEntry = e.getBnfEntry();
|
---|
43 | int _size = _bnfEntry.size();
|
---|
44 | boolean _notEquals = (_size != 0);
|
---|
45 | if (_notEquals) {
|
---|
46 | String _name = e.getName();
|
---|
47 | String _plus = (_name + ".fo");
|
---|
48 | CharSequence _compile = this.compile(e);
|
---|
49 | fsa.generateFile(_plus, _compile);
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public CharSequence compile(final EtsiBnf bnf) {
|
---|
55 | StringConcatenation _builder = new StringConcatenation();
|
---|
56 | _builder.append("<?xml version=\"1.0\"?>");
|
---|
57 | _builder.newLine();
|
---|
58 | _builder.append("<!-- fop ");
|
---|
59 | String _name = bnf.getName();
|
---|
60 | _builder.append(_name, "");
|
---|
61 | _builder.append(".xml -rtf ");
|
---|
62 | String _name_1 = bnf.getName();
|
---|
63 | _builder.append(_name_1, "");
|
---|
64 | _builder.append(".rtf -->");
|
---|
65 | _builder.newLineIfNotEmpty();
|
---|
66 | _builder.append("<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">");
|
---|
67 | _builder.newLine();
|
---|
68 | _builder.newLine();
|
---|
69 | _builder.append("\t");
|
---|
70 | _builder.append("<fo:layout-master-set>");
|
---|
71 | _builder.newLine();
|
---|
72 | _builder.append(" \t\t");
|
---|
73 | _builder.append("<fo:simple-page-master master-name=\"A4\" page-width=\"210mm\" page-height=\"297mm\">");
|
---|
74 | _builder.newLine();
|
---|
75 | _builder.append(" \t\t");
|
---|
76 | _builder.append("<fo:region-body region-name=\"xsl-region-body\" margin=\"2cm\"/>");
|
---|
77 | _builder.newLine();
|
---|
78 | _builder.append(" \t");
|
---|
79 | _builder.append("</fo:simple-page-master>");
|
---|
80 | _builder.newLine();
|
---|
81 | _builder.append("\t");
|
---|
82 | _builder.append("</fo:layout-master-set>");
|
---|
83 | _builder.newLine();
|
---|
84 | _builder.newLine();
|
---|
85 | _builder.append("\t");
|
---|
86 | _builder.append("<fo:page-sequence master-reference=\"A4\">");
|
---|
87 | _builder.newLine();
|
---|
88 | _builder.append("\t\t");
|
---|
89 | _builder.append("<fo:flow flow-name=\"xsl-region-body\" font-family=\"verdana\">");
|
---|
90 | _builder.newLine();
|
---|
91 | {
|
---|
92 | EList<BnfEntry> _bnfEntry = bnf.getBnfEntry();
|
---|
93 | for(final BnfEntry bnfentry : _bnfEntry) {
|
---|
94 | _builder.append("\t\t\t");
|
---|
95 | CharSequence _compile = this.compile(bnfentry);
|
---|
96 | _builder.append(_compile, "\t\t\t");
|
---|
97 | _builder.newLineIfNotEmpty();
|
---|
98 | }
|
---|
99 | }
|
---|
100 | _builder.append("\t\t");
|
---|
101 | _builder.append("</fo:flow>");
|
---|
102 | _builder.newLine();
|
---|
103 | _builder.append("\t");
|
---|
104 | _builder.append("</fo:page-sequence>");
|
---|
105 | _builder.newLine();
|
---|
106 | _builder.append("</fo:root>");
|
---|
107 | return _builder;
|
---|
108 | }
|
---|
109 |
|
---|
110 | public CharSequence compile(final BnfEntry bnfEntry) {
|
---|
111 | StringConcatenation _builder = new StringConcatenation();
|
---|
112 | {
|
---|
113 | Rule _rule = bnfEntry.getRule();
|
---|
114 | boolean _notEquals = (!Objects.equal(_rule, null));
|
---|
115 | if (_notEquals) {
|
---|
116 | Rule _rule_1 = bnfEntry.getRule();
|
---|
117 | CharSequence _compile = this.compile(_rule_1);
|
---|
118 | _builder.append(_compile, "");
|
---|
119 | _builder.newLineIfNotEmpty();
|
---|
120 | }
|
---|
121 | }
|
---|
122 | return _builder;
|
---|
123 | }
|
---|
124 |
|
---|
125 | public CharSequence compile(final Rule rule) {
|
---|
126 | StringConcatenation _builder = new StringConcatenation();
|
---|
127 | _builder.append("<fo:block><fo:inline id=\"");
|
---|
128 | String _name = rule.getName();
|
---|
129 | _builder.append(_name, "");
|
---|
130 | _builder.append("\"\tcolor=\"purple\">");
|
---|
131 | {
|
---|
132 | int _rulenumber = rule.getRulenumber();
|
---|
133 | boolean _notEquals = (_rulenumber != 0);
|
---|
134 | if (_notEquals) {
|
---|
135 | int _rulenumber_1 = rule.getRulenumber();
|
---|
136 | _builder.append(_rulenumber_1, "");
|
---|
137 | _builder.append(".\\t");
|
---|
138 | }
|
---|
139 | }
|
---|
140 | String _name_1 = rule.getName();
|
---|
141 | _builder.append(_name_1, "");
|
---|
142 | _builder.append("</fo:inline>\t::=\t");
|
---|
143 | DefinitionList _definitionList = rule.getDefinitionList();
|
---|
144 | CharSequence _compile = this.compile(_definitionList);
|
---|
145 | _builder.append(_compile, "");
|
---|
146 | _builder.append("</block>");
|
---|
147 | return _builder;
|
---|
148 | }
|
---|
149 |
|
---|
150 | public CharSequence compile(final DefinitionList dList) {
|
---|
151 | StringConcatenation _builder = new StringConcatenation();
|
---|
152 | {
|
---|
153 | EList<SingleDefinition> _singleDefinition = dList.getSingleDefinition();
|
---|
154 | for(final SingleDefinition sDef : _singleDefinition) {
|
---|
155 | CharSequence _compile = this.compile(sDef);
|
---|
156 | _builder.append(_compile, "");
|
---|
157 | {
|
---|
158 | EList<SingleDefinition> _singleDefinition_1 = dList.getSingleDefinition();
|
---|
159 | SingleDefinition _last = IterableExtensions.<SingleDefinition>last(_singleDefinition_1);
|
---|
160 | boolean _equals = sDef.equals(_last);
|
---|
161 | boolean _not = (!_equals);
|
---|
162 | if (_not) {
|
---|
163 | _builder.append(" | ");
|
---|
164 | }
|
---|
165 | }
|
---|
166 | }
|
---|
167 | }
|
---|
168 | return _builder;
|
---|
169 | }
|
---|
170 |
|
---|
171 | public CharSequence compile(final SingleDefinition sDefinition) {
|
---|
172 | StringConcatenation _builder = new StringConcatenation();
|
---|
173 | {
|
---|
174 | EList<Term> _terms = sDefinition.getTerms();
|
---|
175 | for(final Term term : _terms) {
|
---|
176 | CharSequence _compile = this.compile(term);
|
---|
177 | _builder.append(_compile, "");
|
---|
178 | }
|
---|
179 | }
|
---|
180 | return _builder;
|
---|
181 | }
|
---|
182 |
|
---|
183 | public CharSequence compile(final Term term) {
|
---|
184 | StringConcatenation _builder = new StringConcatenation();
|
---|
185 | {
|
---|
186 | Atom _termAtom = term.getTermAtom();
|
---|
187 | boolean _notEquals = (!Objects.equal(_termAtom, null));
|
---|
188 | if (_notEquals) {
|
---|
189 | Atom _termAtom_1 = term.getTermAtom();
|
---|
190 | CharSequence _compile = this.compile(_termAtom_1);
|
---|
191 | _builder.append(_compile, "");
|
---|
192 | }
|
---|
193 | }
|
---|
194 | {
|
---|
195 | OptionalSequence _termOptionalSequence = term.getTermOptionalSequence();
|
---|
196 | boolean _notEquals_1 = (!Objects.equal(_termOptionalSequence, null));
|
---|
197 | if (_notEquals_1) {
|
---|
198 | OptionalSequence _termOptionalSequence_1 = term.getTermOptionalSequence();
|
---|
199 | CharSequence _compile_1 = this.compile(_termOptionalSequence_1);
|
---|
200 | _builder.append(_compile_1, "");
|
---|
201 | }
|
---|
202 | }
|
---|
203 | {
|
---|
204 | RepeatedSequence _termRepeatedSequence = term.getTermRepeatedSequence();
|
---|
205 | boolean _notEquals_2 = (!Objects.equal(_termRepeatedSequence, null));
|
---|
206 | if (_notEquals_2) {
|
---|
207 | RepeatedSequence _termRepeatedSequence_1 = term.getTermRepeatedSequence();
|
---|
208 | CharSequence _compile_2 = this.compile(_termRepeatedSequence_1);
|
---|
209 | _builder.append(_compile_2, "");
|
---|
210 | }
|
---|
211 | }
|
---|
212 | {
|
---|
213 | GroupedSequence _termGroupedSequence = term.getTermGroupedSequence();
|
---|
214 | boolean _notEquals_3 = (!Objects.equal(_termGroupedSequence, null));
|
---|
215 | if (_notEquals_3) {
|
---|
216 | GroupedSequence _termGroupedSequence_1 = term.getTermGroupedSequence();
|
---|
217 | CharSequence _compile_3 = this.compile(_termGroupedSequence_1);
|
---|
218 | _builder.append(_compile_3, "");
|
---|
219 | }
|
---|
220 | }
|
---|
221 | return _builder;
|
---|
222 | }
|
---|
223 |
|
---|
224 | public CharSequence compile(final GroupedSequence gSequ) {
|
---|
225 | StringConcatenation _builder = new StringConcatenation();
|
---|
226 | {
|
---|
227 | EList<DefinitionList> _definitionList = gSequ.getDefinitionList();
|
---|
228 | for(final DefinitionList d : _definitionList) {
|
---|
229 | Object _compile = this.compile(d);
|
---|
230 | _builder.append(_compile, "");
|
---|
231 | }
|
---|
232 | }
|
---|
233 | return _builder;
|
---|
234 | }
|
---|
235 |
|
---|
236 | public CharSequence compile(final RepeatedSequence rSequ) {
|
---|
237 | StringConcatenation _builder = new StringConcatenation();
|
---|
238 | _builder.append("{");
|
---|
239 | {
|
---|
240 | EList<DefinitionList> _definitions = rSequ.getDefinitions();
|
---|
241 | for(final DefinitionList d : _definitions) {
|
---|
242 | Object _compile = this.compile(d);
|
---|
243 | _builder.append(_compile, "");
|
---|
244 | }
|
---|
245 | }
|
---|
246 | _builder.append("}");
|
---|
247 | {
|
---|
248 | boolean _isMorethanonce = rSequ.isMorethanonce();
|
---|
249 | if (_isMorethanonce) {
|
---|
250 | _builder.append("+");
|
---|
251 | }
|
---|
252 | }
|
---|
253 | return _builder;
|
---|
254 | }
|
---|
255 |
|
---|
256 | public CharSequence compile(final OptionalSequence oSequ) {
|
---|
257 | StringConcatenation _builder = new StringConcatenation();
|
---|
258 | _builder.append("(");
|
---|
259 | {
|
---|
260 | EList<DefinitionList> _definitionList = oSequ.getDefinitionList();
|
---|
261 | for(final DefinitionList d : _definitionList) {
|
---|
262 | Object _compile = this.compile(d);
|
---|
263 | _builder.append(_compile, "");
|
---|
264 | }
|
---|
265 | }
|
---|
266 | _builder.append(")");
|
---|
267 | return _builder;
|
---|
268 | }
|
---|
269 |
|
---|
270 | public CharSequence compile(final Atom atom) {
|
---|
271 | StringConcatenation _builder = new StringConcatenation();
|
---|
272 | {
|
---|
273 | RuleReference _atomRuleReference = atom.getAtomRuleReference();
|
---|
274 | boolean _notEquals = (!Objects.equal(_atomRuleReference, null));
|
---|
275 | if (_notEquals) {
|
---|
276 | RuleReference _atomRuleReference_1 = atom.getAtomRuleReference();
|
---|
277 | CharSequence _compile = this.compile(_atomRuleReference_1);
|
---|
278 | _builder.append(_compile, "");
|
---|
279 | }
|
---|
280 | }
|
---|
281 | {
|
---|
282 | StringRule _atomStringRule = atom.getAtomStringRule();
|
---|
283 | boolean _notEquals_1 = (!Objects.equal(_atomStringRule, null));
|
---|
284 | if (_notEquals_1) {
|
---|
285 | StringRule _atomStringRule_1 = atom.getAtomStringRule();
|
---|
286 | CharSequence _compile_1 = this.compile(_atomStringRule_1);
|
---|
287 | _builder.append(_compile_1, "");
|
---|
288 | }
|
---|
289 | }
|
---|
290 | return _builder;
|
---|
291 | }
|
---|
292 |
|
---|
293 | public CharSequence compile(final RuleReference rRef) {
|
---|
294 | StringConcatenation _builder = new StringConcatenation();
|
---|
295 | _builder.append("<fo:basic-link internal-destination=\"");
|
---|
296 | Rule _ruleref = rRef.getRuleref();
|
---|
297 | String _name = _ruleref.getName();
|
---|
298 | _builder.append(_name, "");
|
---|
299 | _builder.append("\" text-decoration=\"underline\" color=\"blue\">");
|
---|
300 | Rule _ruleref_1 = rRef.getRuleref();
|
---|
301 | String _name_1 = _ruleref_1.getName();
|
---|
302 | _builder.append(_name_1, "");
|
---|
303 | _builder.append("</fo:basic-link>");
|
---|
304 | return _builder;
|
---|
305 | }
|
---|
306 |
|
---|
307 | public CharSequence compile(final StringRule sRule) {
|
---|
308 | StringConcatenation _builder = new StringConcatenation();
|
---|
309 | {
|
---|
310 | String _colon = sRule.getColon();
|
---|
311 | boolean _notEquals = (!Objects.equal(_colon, null));
|
---|
312 | if (_notEquals) {
|
---|
313 | String _colon_1 = sRule.getColon();
|
---|
314 | _builder.append(_colon_1, "");
|
---|
315 | }
|
---|
316 | }
|
---|
317 | {
|
---|
318 | String _literal = sRule.getLiteral();
|
---|
319 | boolean _notEquals_1 = (!Objects.equal(_literal, null));
|
---|
320 | if (_notEquals_1) {
|
---|
321 | String _literal_1 = sRule.getLiteral();
|
---|
322 | _builder.append(_literal_1, "");
|
---|
323 | }
|
---|
324 | }
|
---|
325 | return _builder;
|
---|
326 | }
|
---|
327 | }
|
---|