| 1 | /* |
|---|
| 2 | * generated by Xtext |
|---|
| 3 | */
|
|---|
| 4 | package de.ugoe.cs.swe.bnftools.generator
|
|---|
| 5 |
|
|---|
| 6 | import org.eclipse.emf.ecore.resource.Resource
|
|---|
| 7 | import org.eclipse.xtext.generator.IGenerator
|
|---|
| 8 | import org.eclipse.xtext.generator.IFileSystemAccess
|
|---|
| 9 | import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf
|
|---|
| 10 | import de.ugoe.cs.swe.bnftools.ebnf.BnfEntry
|
|---|
| 11 | import de.ugoe.cs.swe.bnftools.ebnf.Rule
|
|---|
| 12 | import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList
|
|---|
| 13 | import de.ugoe.cs.swe.bnftools.ebnf.SingleDefinition
|
|---|
| 14 | import de.ugoe.cs.swe.bnftools.ebnf.Term
|
|---|
| 15 | import de.ugoe.cs.swe.bnftools.ebnf.GroupedSequence
|
|---|
| 16 | import de.ugoe.cs.swe.bnftools.ebnf.Atom
|
|---|
| 17 | import de.ugoe.cs.swe.bnftools.ebnf.RepeatedSequence
|
|---|
| 18 | import de.ugoe.cs.swe.bnftools.ebnf.OptionalSequence
|
|---|
| 19 | import de.ugoe.cs.swe.bnftools.ebnf.RuleReference
|
|---|
| 20 | import de.ugoe.cs.swe.bnftools.ebnf.StringRule
|
|---|
| 21 |
|
|---|
| 22 | /** |
|---|
| 23 | * Generates code from your model files on save. |
|---|
| 24 | * |
|---|
| 25 | * see http://www.eclipse.org/Xtext/documentation.html#TutorialCodeGeneration |
|---|
| 26 | */
|
|---|
| 27 | class EbnfGenerator implements IGenerator {
|
|---|
| 28 | //generation of the file
|
|---|
| 29 | override void doGenerate(Resource resource, IFileSystemAccess fsa) {
|
|---|
| 30 | for (e : resource.allContents.toIterable.filter(EtsiBnf)) {
|
|---|
| 31 | if (e.bnfEntry.size!=0) {
|
|---|
| 32 | fsa.generateFile(e.name + ".fo", e.compile)
|
|---|
| 33 | }
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | |
|---|
| 37 | // compile the different entities of the Bnf-----------------------------------------------------------------------------
|
|---|
| 38 | def compile(EtsiBnf bnf) |
|---|
| 39 | ''' |
|---|
| 40 | <?xml version="1.0"?> |
|---|
| 41 | <!-- fop hello.xml -rtf hello.rtf --> |
|---|
| 42 | <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> |
|---|
| 43 | |
|---|
| 44 | <fo:layout-master-set> |
|---|
| 45 | <fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm"> |
|---|
| 46 | <fo:region-body region-name="xsl-region-body" margin="2cm"/> |
|---|
| 47 | </fo:simple-page-master> |
|---|
| 48 | </fo:layout-master-set> |
|---|
| 49 | |
|---|
| 50 | <fo:page-sequence master-reference="A4"> |
|---|
| 51 | <fo:flow flow-name="xsl-region-body" font-family="verdana"> |
|---|
| 52 | «FOR bnfentry:bnf.bnfEntry» |
|---|
| 53 | «bnfentry.compile» |
|---|
| 54 | «ENDFOR» |
|---|
| 55 | </fo:flow> |
|---|
| 56 | </fo:page-sequence> |
|---|
| 57 | </fo:root>''' |
|---|
| 58 | |
|---|
| 59 | def compile(BnfEntry bnfEntry)''' |
|---|
| 60 | «IF bnfEntry.rule!= null» |
|---|
| 61 | «bnfEntry.rule.compile» |
|---|
| 62 | «ENDIF» |
|---|
| 63 | ''' |
|---|
| 64 | |
|---|
| 65 | def compile(Rule rule)'''<fo:block><fo:inline id="«rule.name»" color="purple">«rule.name»</fo:inline> ::= «rule.definitionList.compile»</block>''' |
|---|
| 66 | |
|---|
| 67 | def compile(DefinitionList dList)'''«FOR sDef:dList.singleDefinition»«sDef.compile»«IF !sDef.equals(dList.singleDefinition.last)» | «ENDIF»«ENDFOR»''' |
|---|
| 68 | |
|---|
| 69 | def compile(SingleDefinition sDefinition)'''«FOR term:sDefinition.terms»«term.compile»«ENDFOR»''' |
|---|
| 70 | |
|---|
| 71 | def compile(Term term)'''«IF term.termAtom!=null»«term.termAtom.compile»«ENDIF»«IF term.termOptionalSequence!=null»«term.termOptionalSequence.compile»«ENDIF»«IF term.termRepeatedSequence!=null»«term.termRepeatedSequence.compile»«ENDIF»«IF term.termGroupedSequence!=null»«term.termGroupedSequence.compile»«ENDIF»''' |
|---|
| 72 | |
|---|
| 73 | def compile(GroupedSequence gSequ)'''«FOR d :gSequ.definitionList»«d.compile»«ENDFOR»'''
|
|---|
| 74 | |
|---|
| 75 | def compile(RepeatedSequence rSequ)'''{«FOR d:rSequ.definitions»«d.compile»«ENDFOR»}«IF rSequ.morethanonce»+«ENDIF»''' |
|---|
| 76 | |
|---|
| 77 | def compile(OptionalSequence oSequ)'''(«FOR d:oSequ.definitionList»«d.compile»«ENDFOR»)''' |
|---|
| 78 | |
|---|
| 79 | def compile(Atom atom)''' |
|---|
| 80 | «IF atom.atomRuleReference!= null»«atom.atomRuleReference.compile»«ENDIF»«IF atom.atomStringRule!= null»«atom.atomStringRule.compile»«ENDIF»''' |
|---|
| 81 | |
|---|
| 82 | def compile(RuleReference rRef)'''<fo:basic-link internal-destination="«rRef.ruleref.name»" text-decoration="underline" color="blue">«rRef.ruleref.name»</fo:basic-link>''' |
|---|
| 83 | |
|---|
| 84 | def compile(StringRule sRule)'''«IF sRule.colon!=null»«sRule.colon»«ENDIF»«IF sRule.literal!=null»«sRule.literal»«ENDIF»''' |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | }
|
|---|