Changes between Version 7 and Version 8 of Developer


Ignore:
Timestamp:
11/04/14 16:12:35 (10 years ago)
Author:
phdmakk
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Developer

    v7 v8  
    11= Developer Guide BNF Tools = 
    2 BNF Tools is a BNF-Editor based on xText DSLs, which gives away alot of features. 
    3  
    4 == The used Features are: == 
    5  * Grammardefinition 
    6  
     2 
     3BNF Tools is a BNF editor and IDE based on xText. 
     4 
     5== Overview == 
     6 
     7This documentation includes hints related to the deployment of the tools as well as to the implementation of the following features: 
     8 
     9 * Grammar definition and code generation 
    710 * Validation 
    8  
    9  * Quickfixing 
    10  
     11 * Quick-fixing 
    1112 * Generation of content from the BNF 
    12  
    1313 * Formatting 
    14  
    1514 * Outlining 
    16  
    1715 * File import 
    18  
    1916 * Deployment as Plugin 
    20  
    2117 * Deployment as RCP (Rich Client Platform) 
    2218 
    23 == Grammardefinition: == 
    24 The corefeature of  xText. 
    25  
    26 This is defined in de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.bnftools.ebnf/EBNF.xtext 
    27  
    28 IT contains the Entities after which the grammar must be defined, while the first rule is the Start e.g.: 
     19== Grammar Definition and Code Generation == 
     20 
     21The xText grammer is defined in `de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.bnftools.ebnf/EBNF.xtext`. The first rule is the Start e.g.: 
    2922 
    3023{{{ 
     
    4639        ) 
    4740; 
    48  
    49  
    50 }}} 
    51 To turn this into a runable application  the .mwe2 file in the same folder must be executed as MWE2 Workflow.After this the whole project can be executed as an Eclipse Application for testing: 
    52  
    53 == Validation allows to check for conditions in the BNF-Document: == 
    54 In the File  de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.validation/!EbnfValidator.xtend 
    55  
    56 validationrules can be defined e.g.: 
     41}}} 
     42 
     43To turn this into a runable application the .mwe2 file in the same folder must be executed as MWE2 Workflow. After this, the whole project can be executed as an Eclipse Application for testing. 
     44 
     45== Validation == 
     46 
     47Validation allows to check for constraints and conditions within the BNF-Document. Validation rules can be defined in Xtend according to the general framework provided by xText in the file  `de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.validation/EbnfValidator.xtend`, e.g.: 
    5748 
    5849{{{ 
     
    6657        } 
    6758}}} 
    68 The parameter can be any Entity from the previously defined Grammar and every Entity of this Type will be checked this way. 
    69  
    70 And if the Check finds some inconsistency awarningwill be displayed to this Entity Instance in the Editor. 
    71  
    72 The other files in the Package contain supporting Methodes for the validation 
    73  
    74 like 
    75  
    76 {{{ 
    77 EbnfAnalysisUtils.findReferences(rule); 
    78 }}} 
    79 or 
    80  
    81 {{{ 
    82 EbnfAnalysisUtils.findReferences(rule,resourceDescriptions); 
    83 }}} 
    84 Which find the Rule references inside a BNF-File or outside a BNF-File. 
    85  
    86 == Quickfixing can be applied to warnings given by Validations: == 
    87 In the File  de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.quickfix/!EbnfQuickfixProvider.xtend 
    88  
    89 quickfixes for validation-warnings can be defined e.g.: 
     59 
     60The parameter can be any entity type from the previously defined grammar and the validation rule will be applied on every entity of this type. If the validation conditions are not met,  a warning message will be produced and displayed next to the violating entity Instance in the editor. The other files in the package contain supporting methods for the validation, such as  
     61`EbnfAnalysisUtils.findReferences(rule)` or `EbnfAnalysisUtils.findReferences(rule,resourceDescriptions)`, which provide functionality for finding rule references within a BNF file or within a set of BNF files. 
     62 
     63== Quick-fixing == 
     64 
     65Quick-fixing can be applied to warnings raised by violations of validation constraints. Quick-fixes can be defined in Xtend according to the general framework provided by xText in the file  `de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.quickfix/EbnfQuickfixProvider.xtend`, e.g.: 
    9066 
    9167{{{ 
     
    10581        } 
    10682}}} 
    107 The@Fix(''String token'')annotation definies that the following method is a quickfix for a validationwarning, with that''token''as code parameter: 
     83 
     84The `@Fix(EbnfValidator.unusedRuleDescription)` annotation identifies the following method as a quick-fix for the corresponding validation warning, i.e. `EbnfValidator.unusedRuleDescription` in this case, which is raised by the validation rule defined above: 
    10885 
    10986{{{ 
    11087warning(unusedRuleDescription, EbnfPackage$Literals::RULE__NAME, unusedRuleDescription, rule.name); 
    11188}}} 
    112 {{{ 
    113 @Fix(EbnfValidator.unusedRuleDescription) 
    114 }}} 
    115 The accaptor inside applies the changes, via two possible ways: 
    116  
    117  1. Change the Document itself (like the example shows). 
    118  
    119  1. Change the underlying ecoremodel. 
    120  
    121 == Generation allows to generate other files from a BNF-Document: == 
    122 In our case we create a .fo document, that can be transformed into a PDF-Document using Apache FOP. 
    123  
    124 It can be customized in the File  de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/!EbnfGenerator.xtend 
    125  
    126 Where thedoGeneratemethode defines how the files given by a Resource and a !IfileSystemAccess should generate a new file. While for every relevant Entity from the 
    127  
    128 BNF a compile Methode handles the generation in the new file, while it calls the compile Methode for every related Entity e.g.: 
    129  
    130 {{{ 
    131 def void doGenerate(Resource resource, IFileSystemAccess fsa,boolean mode) { 
     89 
     90The acceptor inside applies the changes in two possible ways: 
     91 
     92 1. Change the Document itself (as shown in the example). 
     93 
     94 1. Change the underlying Ecore model. 
     95 
     96== Generation == 
     97 
     98Generation allows the user to generate other files from a BNF document. In our case we create an intermediate `.fo` document, that can be transformed into a PDF or an RTF document by using Apache FOP. The generation of the intermediate `.fo` document can be customised in Xtend according to the general framework provided by Xtext in the file `de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/EbnfGenerator.xtend`. 
     99 
     100The `doGenerate` method defines how the file described by a `Resource` and an `IFileSystemAccess` shall be processed in order generate a new file in the target format. The `compile` methods then handle the transformation, for each relevant entity instance and all related entity instances, e.g.: 
     101 
     102{{{ 
     103def void doGenerate(Resource resource, IFileSystemAccess fsa, boolean mode) { 
    132104                var String workspacePath = WorkspaceResolver.getWorkspace(); 
    133105                for (e : resource.allContents.toIterable.filter(EtsiBnf)) { 
     
    138110        } 
    139111}}} 
    140 Based on the generated .fo file a PDF-document can be generated for this the class de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/foToPDF can be used, either by giving the .fo file and the output URI without Ending or simply the giving the classpath of the file. 
    141  
    142 For this the doGenerateMethode needed an upgrade to access the filesystem via URIs: 
    143  
    144 {{{ 
    145 def void doGenerate(Resource resource, IFileSystemAccess fsa,boolean mode) { 
     112 
     113Based on the generated .fo file a PDF document can be generated with the help of the `de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/foToPDF` class, either by providing the .fo file and the output URI without ending or simply by providing the path of the file. To enable this, the `doGenerate` method needs an upgrade to access the filesystem via URIs: 
     114 
     115{{{ 
     116def void doGenerate(Resource resource, IFileSystemAccess fsa, boolean mode) { 
    146117                var String workspacePath = WorkspaceResolver.getWorkspace(); 
    147118                for (e : resource.allContents.toIterable.filter(EtsiBnf)) { 
     
    157128                                        //true -> pdf, false -> rtf 
    158129                                         
    159                                         if(mode){ 
     130                                        if (mode) { 
    160131                                                FoToPdfOrRtf.createRtfFromFo(fullUri.substring(0, fullUri.length - 3)); 
    161                                         }else{ 
     132                                        } else { 
    162133                                                FoToPdfOrRtf.createPdfFromFo(fullUri.substring(0, fullUri.length - 3)); 
    163134                                        } 
     
    169140        } 
    170141}}} 
    171 To include apache fop you need to add all the jars in a folder e.g. Libs in your project, add this folder to your buildpath, cofigure buildpath and add the jars to it and add them in the plugin.xml on the page runtime at classpath. 
    172  
    173 == Formatting or Prittey Printing is to format the BNF-Document: == 
    174 In the File de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.formatting/!EbnfFormatter.xtend 
    175  
    176 the Method configureFormatting(!FormattingConfig c)allows to define formatting rules 
    177  
    178 before, after or between Enteties or Keywords. 
    179  
    180 e.g.: 
    181  
    182 {{{ 
    183 @Inject extension EbnfGrammarAccess override protected voidconfigureFormatting(FormattingConfig c) 
     142 
     143The Apache FOP libraries need to be added to the build path and the plugin dependencies. 
     144 
     145== Formatting == 
     146 
     147Formatting (or pretty-printing) can be used to automatically format the BNF document by inserting white space where appropriate in order to improve the readability of the document. Formatting can be defined in Xtend according to the general framework provided by Xtext by adapting the file `de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.formatting/EbnfFormatter.xtend`. The method `configureFormatting(FormattingConfig c)` describes the formatting rules before, after, or between entity instances or keywords, e.g.: 
     148 
     149{{{ 
     150@Inject extension EbnfGrammarAccess  
     151override protected void configureFormatting(FormattingConfig c) 
    184152{ 
    185153        c.setLinewrap(0,1,2).before(SL_COMMENTRule); 
     
    187155        c.setLinewrap(0,1,1).after(ML_COMMENTRule); 
    188156        var EbnfGrammarAccess f = getGrammarAccess as EbnfGrammarAccess;c.setLinewrap.before(f.ruleRule); 
    189         c.setLinewrap.before(f.importRule);c.setNoSpace.after(f.ruleAccess.rulenumberINTTerminalRuleCall_0_0_0); 
     157        c.setLinewrap.before(f.importRule);c.setNoSpace.after(f.ruleAccess.rulenumberINTTerminalRuleCall_0_0_0); 
    190158} 
    191159}}} 
    192 The Entities are recieved via  an Inector that gives access to The Grammar. 
    193  
    194 == Outlining and Labeling are Features, that show the document Structure of the BNF-Document: == 
    195 Outlinining can be customized in the File 
    196  
    197 de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.outline/!EbnfOutlineTreeProvider.xtend. 
    198  
    199 Here you can define a_createChildren()with the rootNode and the BNF-Entity of the Grammar to change the outline sequence: 
     160 
     161== Outlining == 
     162 
     163Outlining and labelling are features that show the document structure of the BNF document. Outlining can be customised in Xtend according to the general framework provided by xText in the file `de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.outline/EbnfOutlineTreeProvider.xtend`. There a `createChildren()` method with `rootNode` and the BNF entity of the grammar as parameters can be defined to change the outline sequence: 
    200164 
    201165{{{ 
     
    204168} 
    205169}}} 
    206 Labeling is made to customize what the outline text for an Entity should look like. 
    207  
    208 It can be customized in the file 
    209  
    210 de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.labeling/!EbnfLabelProvider.xtend 
    211  
    212 Where for every Entity a text can be defined: 
     170 
     171Labelling can be customised in Xtend according to the general framework provided by xText in the file `de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.labeling/EbnfLabelProvider.xtend` in order to customise what the outline text for an entity should look like, e.g.: 
    213172 
    214173{{{ 
    215174def text(ImportSection sec){'Imports'} 
    216175}}} 
    217 == File import allows to reference Rules from one BNF-Document in another: == 
    218 There are 2 ways for imports, via URI and VIA Namespaces: 
    219  
    220 The BNF-Grammar uses the URI version. To Activate this the lines 
     176 
     177== File Imports == 
     178File imports allow referencing rules from one BNF document into another. There are two ways for imports, via URIs and via name-space. The BNF grammar uses the URI-based approach. To activate this the lines 
    221179 
    222180{{{ 
     
    226184fragment= types.[wiki:TypesGeneratorFragmentauto]-inject{} 
    227185}}} 
    228 in the .mwe2 file have to be commented out and the lines: 
     186 
     187in the `.mwe2` file need to be commented out and the lines: 
    229188 
    230189{{{ 
     
    232191fragment= exporting.SimpleNamesFragmentauto-inject{} 
    233192}}} 
    234 must be included. 
    235  
    236 After That imports can be defined like this and will automaticly be used: 
     193 
     194need to be included, after which imports can be defined in the grammar, e.g.: 
    237195 
    238196{{{ 
    239197'import' importURI = STRING 
    240198}}} 
    241 == Also it is possible to add features to the UI via Xtext: == 
    242 Therefor i recomend reading this Guide http://flipsomel.wordpress.com/. 
    243  
    244 But don't use the @Override annotation! 
    245  
    246 == Deployment as Plugin: == 
    247 If you want to deploy your the BNF Tools you can use the deployment as plugin: 
    248  
    249 Rightclick your xTextProject, choose __export__, choose __Plug-in development --> Deployable plug-ins and fragments__, choose all parts of the project, *.ebnf *.ebnf.tests *.ebnf.ui and a directory. After you finish this will generate a jar for every one of the choosen projects. Add these to the pluigin-folder of a eclipse and it should be installed 
    250  
    251 == Deployment as RCP: == 
    252 If you want to create a Rich client platform for a standalone minimal worbench setup with only your plugin an requiered plugins in it RCP is a good choice (This is for an eclipse 3.x RCP). 
    253  
    254 First create your __xText Project__, then create a new __Plug-in Project__. Give it a name, 
    255  
    256 e.g. de.ugoe.cs.swe.bnftools.ebnf.product. Click next, and unchoose __Generate an Activator, a Java Class that controls the plug-in-s life cycle__ and __This plug-in will make contributions to the UI__. Also choose __no__ at __Rich client Platform__. Press finish. 
    257  
    258 now open the __Manifest.MF__, go to the __Overview page__ and choose __This plug-in in a singleton__. Then go to the __Dependencies page__ and add __org.eclipse.core.runtime__. 
    259  
    260 Now create a product configuration in your product project, on its __Overview Page__click new, choose a fitting name and ID, your product project as defining Plugin and org.eclipse.ui.ide.workbench as application. Now go back to the __Manifest.MF__and open the __Extensions Page__. There you should now see 1 Extension __org.eclipse.core.runtime.products__ with a product inside. This should have __org.eclipse.ui.ide.workbench__ as application and the given name of the product configuration as name. Rightclick the product and create a new property and if you want you can give it a customized name and value. 
    261  
    262 Now back to the p __roduct configuration__ and its dependencies page. There you add all your xtext projects and your product, then click __add Requiered Plug-ins__. After this you still need to add the Plugins __org.eclipse.ui.ide.application__ and __org.eclipse.core.net__. Now you can test your product by running it as a Runtime Eclipse, if there is a missing plugin you can find it using the_ _validate plugins option__ in the run configurations plug-ins page . Deploy it using __Export as an Eclipse Product__ in the __product configuration__.__ 
    263  
    264 @ To make the generator run properly you need to add org.eclipse.xtext.xbase to your product configuration dependencies 
     199 
     200 
     201== Generation UI == 
     202 
     203 
     204See the guide at http://flipsomel.wordpress.com/ (skip the @Override annotations). 
     205 
     206TODO: Transfer relevant instructions. 
     207 
     208== Deployment as Plugin == 
     209 
     210The simplest way to deploy the BNF Tools is to deploy them as a plugin: 
     211 
     212 * Right click the xTextProject --> Export... --> Plug-in Development --> Deployable plug-ins and fragments 
     213 * Choose all parts of the project, *.ebnf *.ebnf.tests *.ebnf.ui and an output location.  
     214 * Click finish.  
     215 * Transfer the generated JARs in the output location to the pluigin-folder of the target Eclipse distribution and it should be installed. 
     216 
     217== Deployment as RCP == 
     218 
     219A more portable way to deploy the BNF Tools is as a standalone Rich Client Platform (RCP) application. This results in a  standalone minimal workbench setup with only the BNF plugin and required dependencies.  
     220 
     221 * Create a new Plug-in Project e.g. `de.ugoe.cs.swe.bnftools.ebnf.product`. Click next, and uncheck ''Generate an Activator'', a Java class that controls the plug-in's life cycle and ''This plug-in will make contributions to the UI''. Also choose ''no'' at ''Rich Client Platform''. Press finish. 
     222 * Open the `MANIFEST.MF` of the newly created project, go to the ''Overview'' page and choose ''This plug-in in a singleton'', then go to the ''Dependencies'' page and add `org.eclipse.core.runtime`. 
     223 * Create a product configuration in your product project 
     224  * On its ''Overview'' page, click ''New'', choose a fitting ''name'' and ''ID'', select the product project as ''defining plug-in'' and `org.eclipse.ui.ide.workbench` as ''application''.  
     225 * Go back to the `MANIFEST.MF` and open the ''Extensions'' page. There you should now see one ''Extension'' `org.eclipse.core.runtime.products` with a newly created product inside. This should have `org.eclipse.ui.ide.workbench` as ''application'' and the given name of the product configuration as ''name''.  
     226  * Right-click on the product and create a new ''property'' and optionally give it a customised ''name'' and ''value''. 
     227 * Go back to the product configuration and its ''Dependencies'' page.  
     228  * Add all the xText projects and the newly created product, then click ''Add required plug-ins''.  
     229  * Manually add the plug-ins `org.eclipse.ui.ide.application` and `org.eclipse.core.net`. 
     230  * To make the generator run properly, manually add also `org.eclipse.xtext.xbase` to the dependencies. 
     231 * Test your product by running it as a ''Runtime Eclipse Application''. 
     232  * If there is a missing plug-in you can find it using the ''Validate plug-ins'' option in the run configurations plug-ins page. 
     233 * Deploy it using ''Export as an Eclipse Product'' in the product configuration.