[61] | 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
|
---|
[65] | 21 | import java.io.File
|
---|
[69] | 22 | import org.eclipse.xtext.generator.IFileSystemAccessExtension2
|
---|
| 23 | import org.eclipse.emf.common.util.URI; |
---|
[70] | 24 | import org.eclipse.xtext.generator.IFileSystemAccessExtension
|
---|
| 25 | import java.io.PrintWriter |
---|
[61] | 26 | /** |
---|
| 27 | * Generates code from your model files on save. |
---|
| 28 | * |
---|
| 29 | * see http://www.eclipse.org/Xtext/documentation.html#TutorialCodeGeneration |
---|
| 30 | */
|
---|
| 31 | class EbnfGenerator implements IGenerator {
|
---|
[63] | 32 | //generation of the xsl-file
|
---|
[70] | 33 | override void doGenerate(Resource resource, IFileSystemAccess fsa) { |
---|
| 34 | var String workspacePath =WorkspaceResolver.getWorkspace();
|
---|
[61] | 35 | for (e : resource.allContents.toIterable.filter(EtsiBnf)) {
|
---|
| 36 | if (e.bnfEntry.size!=0) {
|
---|
[69] | 37 | fsa.generateFile(e.name + ".fo", e.compile) |
---|
| 38 | |
---|
| 39 | //generate pdf |
---|
[70] | 40 | var uri = (fsa as IFileSystemAccessExtension2).getURI(e.name+".fo"); |
---|
| 41 | var String fullUri = workspacePath+uri.path.substring(10,uri.path.length); |
---|
| 42 | System.out.println(workspacePath+uri.path.substring(10,uri.path.length)); |
---|
| 43 | var File file = new File(fullUri); |
---|
| 44 | System.out.println(file.exists); |
---|
[69] | 45 | // System.out.println(uri.toString()); |
---|
[70] | 46 | |
---|
| 47 | |
---|
[69] | 48 | // System.out.println(file.exists); |
---|
[70] | 49 | |
---|
[69] | 50 | // foToPdf.createPdfFromFo(file,aPath.substring(0,aPath.length-3));
|
---|
[61] | 51 | }
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | |
---|
| 55 | // compile the different entities of the Bnf-----------------------------------------------------------------------------
|
---|
| 56 | def compile(EtsiBnf bnf) |
---|
| 57 | ''' |
---|
| 58 | <?xml version="1.0"?> |
---|
[63] | 59 | <!-- fop «bnf.name».xml -rtf «bnf.name».rtf --> |
---|
[61] | 60 | <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> |
---|
| 61 | |
---|
| 62 | <fo:layout-master-set> |
---|
| 63 | <fo:simple-page-master master-name="A4" page-width="210mm" page-height="297mm"> |
---|
| 64 | <fo:region-body region-name="xsl-region-body" margin="2cm"/> |
---|
| 65 | </fo:simple-page-master> |
---|
| 66 | </fo:layout-master-set> |
---|
| 67 | |
---|
| 68 | <fo:page-sequence master-reference="A4"> |
---|
| 69 | <fo:flow flow-name="xsl-region-body" font-family="verdana"> |
---|
[65] | 70 | |
---|
| 71 | <fo:block span="all" text-align="center" text-indent="1em" font-family="Arial" font-size="20pt" font-weight="bold" background-color="#EEEEEE" line-height="20mm">«bnf.name»</fo:block> |
---|
| 72 | |
---|
[61] | 73 | «FOR bnfentry:bnf.bnfEntry» |
---|
| 74 | «bnfentry.compile» |
---|
| 75 | «ENDFOR» |
---|
| 76 | </fo:flow> |
---|
| 77 | </fo:page-sequence> |
---|
| 78 | </fo:root>''' |
---|
| 79 | |
---|
| 80 | def compile(BnfEntry bnfEntry)''' |
---|
| 81 | «IF bnfEntry.rule!= null» |
---|
| 82 | «bnfEntry.rule.compile» |
---|
| 83 | «ENDIF» |
---|
| 84 | ''' |
---|
| 85 | |
---|
[65] | 86 | def compile(Rule rule)'''<fo:block><fo:inline id="«rule.name»" color="purple">«IF rule.rulenumber!=0»«rule.rulenumber». «ENDIF»«rule.name»</fo:inline> ::= «rule.definitionList.compile»</fo:block>''' |
---|
[61] | 87 | |
---|
| 88 | def compile(DefinitionList dList)'''«FOR sDef:dList.singleDefinition»«sDef.compile»«IF !sDef.equals(dList.singleDefinition.last)» | «ENDIF»«ENDFOR»''' |
---|
| 89 | |
---|
| 90 | def compile(SingleDefinition sDefinition)'''«FOR term:sDefinition.terms»«term.compile»«ENDFOR»''' |
---|
| 91 | |
---|
| 92 | 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»''' |
---|
| 93 | |
---|
| 94 | def compile(GroupedSequence gSequ)'''«FOR d :gSequ.definitionList»«d.compile»«ENDFOR»'''
|
---|
| 95 | |
---|
| 96 | def compile(RepeatedSequence rSequ)'''{«FOR d:rSequ.definitions»«d.compile»«ENDFOR»}«IF rSequ.morethanonce»+«ENDIF»''' |
---|
| 97 | |
---|
| 98 | def compile(OptionalSequence oSequ)'''(«FOR d:oSequ.definitionList»«d.compile»«ENDFOR»)''' |
---|
| 99 | |
---|
| 100 | def compile(Atom atom)''' |
---|
| 101 | «IF atom.atomRuleReference!= null»«atom.atomRuleReference.compile»«ENDIF»«IF atom.atomStringRule!= null»«atom.atomStringRule.compile»«ENDIF»''' |
---|
| 102 | |
---|
[65] | 103 | def compile(RuleReference rRef)'''<fo:basic-link internal-destination="«rRef.ruleref.name»" text-decoration="underline" color="blue">«rRef.ruleref.name»</fo:basic-link> ''' |
---|
[61] | 104 | |
---|
[65] | 105 | def compile(StringRule sRule)'''«IF sRule.colon!=null»«sRule.colon»«ENDIF»«IF sRule.literal!=null»«sRule.literal» «ENDIF»''' |
---|
[61] | 106 | |
---|
| 107 | |
---|
| 108 | }
|
---|