Changeset 87 in default


Ignore:
Timestamp:
11/05/14 15:49:44 (9 years ago)
Author:
phdmakk
Message:

+ fixes to generators: correct export to FO, correct paths (especially for imported resources), etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • v2/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/generator/EbnfGenerator.xtend

    r85 r87  
    2222import org.eclipse.xtext.generator.IGenerator 
    2323import de.ugoe.cs.swe.bnftools.ebnf.SectionHeading 
     24import org.eclipse.core.resources.ResourcesPlugin 
    2425 
    2526/** 
     
    3940                                //generate pdf 
    4041                                var uri = (fsa as IFileSystemAccessExtension2).getURI(e.name + ".fo"); 
    41                                 var String fullUri = workspacePath + uri.path.substring(10, uri.path.length); 
    42                                 var File file = new File(fullUri); 
    43  
     42                                var String relativePath = uri.path.substring(10); 
     43                                var String realPath = ResourcesPlugin.getWorkspace().root.findMember(relativePath).rawLocation.toOSString; 
     44                                var File file = new File(realPath); 
    4445                                if (file.exists) { 
    4546                                        //true -> pdf, false -> rtf 
    4647                                         
    4748                                        if(mode){ 
    48                                                 FoToPdfOrRtf.createRtfFromFo(fullUri.substring(0, fullUri.length - 3)); 
     49                                                FoToPdfOrRtf.createRtfFromFo(realPath.substring(0, realPath.length - 3)); 
    4950                                        }else{ 
    50                                                 FoToPdfOrRtf.createPdfFromFo(fullUri.substring(0, fullUri.length - 3)); 
     51                                                FoToPdfOrRtf.createPdfFromFo(realPath.substring(0, realPath.length - 3)); 
    5152                                        } 
    5253                                         
     
    9091         
    9192                <fo:page-sequence  master-reference="A4"> 
    92                         <fo:flow flow-name="xsl-region-body" font-family="verdana"> 
     93                        <fo:flow flow-name="xsl-region-body" font-family="Monospaced" font-size="8pt"> 
    9394                                 
    94                                 <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. 
     95                                <fo:block span="all"  text-align="center" text-indent="1em" font-family="Monospaced" font-size="20pt" font-weight="bold" background-color="#EEEEEE" line-height="20mm">«bnf. 
    9596                name»</fo:block> 
    9697                                                 
     
    113114        def compile(SectionHeading sHeading) ''' 
    114115                 
    115                 <fo:block role="H1" font-weight="bold"> «sHeading.sectionHeader» </fo:block> 
     116                <fo:block role="H1" font-family="SansSerif" font-size="12pt" line-height="2em"> «sHeading.sectionHeader» </fo:block> 
    116117                 
    117118        ''' 
    118119 
    119         def compile(Rule rule) '''«System.out.println(rule.name)»<fo:block><fo:inline id="«rule.name»"  color="purple">«IF rule.rulenumber != 0»«rule. 
     120        def compile(Rule rule) '''<fo:block><fo:inline id="«rule.name»" color="black">«IF rule.rulenumber != 0»«rule. 
    120121                rulenumber».    «ENDIF»«rule.name»</fo:inline>  ::=     «rule.definitionList.compile»</fo:block>''' 
    121122 
    122         def compile(DefinitionList dList) '''«IF dList!= null»«FOR sDef : dList.singleDefinition»«sDef.compile»«IF !sDef.equals( 
    123                 dList.singleDefinition.last)» | «ENDIF»«ENDFOR»«ENDIF»''' 
     123        def compile(DefinitionList dList) '''«IF dList!= null»«FOR sDef : dList.singleDefinition»«sDef.compile+" "»«IF !sDef.equals( 
     124                dList.singleDefinition.last)»| «ENDIF»«ENDFOR»«ENDIF»''' 
    124125 
    125126        def compile(SingleDefinition sDefinition) '''«FOR term : sDefinition.terms»«term.compile»«ENDFOR»''' 
     
    127128        def compile(Term term) '''«IF term.termAtom != null»«term.termAtom.compile»«ENDIF»«IF term.termOptionalSequence != 
    128129                null»«term.termOptionalSequence.compile»«ENDIF»«IF term.termRepeatedSequence != null»«term.termRepeatedSequence. 
    129                 compile»«ENDIF»«IF term.termGroupedSequence != null»«term.termGroupedSequence.compile»«ENDIF»''' 
     130                compile»«ENDIF»«IF term.termGroupedSequence != null»«term.termGroupedSequence.compile»«ENDIF» ''' 
    130131 
    131         def compile(GroupedSequence gSequ) '''«FOR d : gSequ.definitionList»«d.compile»«ENDFOR»''' 
     132        def compile(GroupedSequence gSequ) '''( «FOR d : gSequ.definitionList»«d.compile+" "»«ENDFOR» )''' 
    132133 
    133         def compile(RepeatedSequence rSequ) '''{«FOR d : rSequ.definitions»«d.compile»«ENDFOR»}«IF rSequ.morethanonce»+«ENDIF»''' 
     134        def compile(RepeatedSequence rSequ) '''{ «FOR d : rSequ.definitions»«d.compile+" "»«ENDFOR» }«IF rSequ.morethanonce»+«ENDIF»''' 
    134135 
    135         def compile(OptionalSequence oSequ) '''(«FOR d : oSequ.definitionList»«d.compile»«ENDFOR»)''' 
     136        def compile(OptionalSequence oSequ) '''[ «FOR d : oSequ.definitionList»«d.compile+" "»«ENDFOR» ]''' 
    136137 
    137138        def compile(Atom atom) ''' 
    138139        «IF atom.atomRuleReference != null»«atom.atomRuleReference.compile»«ENDIF»«IF atom.atomStringRule != null»«atom. 
    139                 atomStringRule.compile»«ENDIF»''' 
     140                atomStringRule.compile»«ENDIF» ''' 
    140141 
    141142        def compile(RuleReference rRef) '''<fo:basic-link internal-destination="«rRef.ruleref.name»" text-decoration="underline" color="blue">«rRef. 
    142                 ruleref.name»</fo:basic-link>   ''' 
     143                ruleref.name»</fo:basic-link> ''' 
    143144 
    144         def compile(StringRule sRule) '''«IF sRule.colon != null»«sRule.colon»«ENDIF»«IF sRule.literal != null»«sRule. 
    145                 literal.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")»  «ENDIF»''' 
     145        def compile(StringRule sRule) '''«IF sRule.colon != null»«sRule.colon»«ENDIF»«IF sRule.literal != null»«'"'+sRule. 
     146                literal.trim.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")+'"'» «ENDIF»''' 
    146147 
    147148} 
Note: See TracChangeset for help on using the changeset viewer.