source: default/v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/xtend-gen/de/ugoe/cs/swe/bnftools/generator/EbnfGenerator.java @ 61

Last change on this file since 61 was 61, checked in by hkaulbersch, 10 years ago

initial commit

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