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