Changes between Initial Version and Version 1 of Developer


Ignore:
Timestamp:
06/25/14 10:05:11 (10 years ago)
Author:
hkaulbersch
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Developer

    v1 v1  
     1__'''Developer Guide BNF Tools'''__ 
     2 
     3BNF Tools is a BNF-Editor based on xText DSLs, which gives away alot of features. 
     4 
     5'''The used Features are:''' 
     6 
     7 
     8 * Grammardefinition 
     9 
     10 
     11 
     12 
     13 * Validation 
     14 
     15 
     16 * Quickfixing 
     17 
     18 
     19 * Generation of content from the BNF 
     20 
     21 
     22 * Formatting 
     23 
     24 
     25 * Outlining 
     26 
     27 
     28 * File import 
     29 
     30 
     31 * Deployment as Plugin 
     32 
     33 
     34 * Deployment as RCP (Rich Client Platform) 
     35 
     36 
     37 
     38'''Grammardefinition:''' 
     39 
     40The corefeature of  xText. 
     41 
     42This is defined in de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.bnftools.ebnf/EBNF.xtext 
     43 
     44IT contains the Entities after which the grammar must be defined, while the first rule is the Start e.g.: 
     45 
     46!EtsiBnf: 
     47 
     48'grammar'name=ID 
     49 
     50(       type='/__bnf__'?';' 
     51 
     52(importSection=!ImportSection)? 
     53 
     54(bnfEntry+=!BnfEntry)+ 
     55 
     56) 
     57 
     58| 
     59 
     60(       type='/delta'';' 
     61 
     62(importSection=!ImportSection)? 
     63 
     64(deltaEntry+=!DeltaEntry)* 
     65 
     66) 
     67 
     68| 
     69 
     70(       type='/merge'';' 
     71 
     72(importSection=!ImportSection)? 
     73 
     74(mergeEntry+=!MergeEntry)* 
     75 
     76) 
     77 
     78; 
     79 
     80To turn this into a runable application  the .mwe2 file in the same folder must be executed as MWE2 Workflow. 
     81 
     82After this the whole project can be executed as an Eclipse Application for testing 
     83 
     84'''Validation allows to check for conditions in the BNF-Document:''' 
     85 
     86In the File  de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.validation/!EbnfValidator.xtend 
     87 
     88validationrules can be defined e.g.: 
     89 
     90@Check 
     91 
     92'''defvoid'''checkUnusedRule(Rule rule) { 
     93 
     94'''var'''List<!RuleReference> references = !EbnfAnalysisUtils.''findReferences''(rule); 
     95 
     96'''var'''List<Rule> references1 =       !EbnfAnalysisUtils.''findReferences''(rule,resourceDescriptions); 
     97 
     98'''if'''((references.size+references1.size ==0) && (rule.getRulenumber() !=1)) 
     99 
     100warning(''unusedRuleDescription'', !EbnfPackage$Literals::''RULE!__NAME'',''unusedRuleDescription'', rule.name); 
     101 
     102} 
     103 
     104For this the@Checkannotation defines that the next function is a Validationcheck. 
     105 
     106The parameter can be any Entity from the previously defined Grammar and every Entity of this Type will be checked this way. 
     107 
     108And if the Check finds some inconsistency awarningwill be displayed to this Entity Instance in the Editor. 
     109 
     110The other files in the Package contain supporting Methodes for the validation 
     111 
     112like 
     113 
     114!EbnfAnalysisUtils.''findReferences''(rule); 
     115 
     116or 
     117 
     118!EbnfAnalysisUtils.''findReferences''(rule,resourceDescriptions); 
     119 
     120Which find the Rule references inside a BNF-File or outside a BNF-File. 
     121 
     122[[BR]]'''Quickfixing can be applied to warnings given by Validations:''' 
     123 
     124In the File  de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.quickfix/!EbnfQuickfixProvider.xtend 
     125 
     126quickfixes for validation-warnings can be defined e.g.: 
     127 
     128@Fix(!EbnfValidator.''unusedRuleDescription'') 
     129 
     130'''defvoid'''fixUnusedRule(Issue issue, !IssueResolutionAcceptor acceptor) { 
     131 
     132acceptor.accept(issue,"Remove unused rule","Delete the unused rule","upcase.png",[ element, context | 
     133 
     134'''var'''Rule rule = element'''as'''Rule; 
     135 
     136'''var'''IXtextDocument xtextDocument = context.getXtextDocument(); 
     137 
     138'''var'''ICompositeNode node = !NodeModelUtils.''findActualNodeFor''(rule); 
     139 
     140'''varint'''offset = node.textRegion.offset; 
     141 
     142'''var'''String nodeText = node.text; 
     143 
     144'''varint'''textLength = nodeText.length -2; 
     145 
     146xtextDocument.replace(offset, textLength,""); 
     147 
     148]) 
     149 
     150} 
     151 
     152The @Fix(''String token'') annotation definies that the following method is a quickfix for a validationwarning, with that ''token'' as code parameter: 
     153 
     154warning(''unusedRuleDescription'', !EbnfPackage$Literals::''RULE!__NAME'',      ''__unusedRuleDescription__'', rule.name); 
     155 
     156@Fix(!EbnfValidator.''__unusedRuleDescription__'') 
     157 
     158The accaptor inside applies the changes, via two possible ways: 
     159 
     160 
     161 1. Change the Document itself (like the example shows). 
     162 
     163 
     164 1. Change the underlying ecoremodel. 
     165 
     166 
     167 
     168[[BR]]'''Generation allows to generate other files from a BNF-Document:''' 
     169 
     170In our case we create a .fo document, that can be transformed into a PDF-Document 
     171 
     172using Apache FOP. 
     173 
     174It can be customized in the File  de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/!EbnfGenerator.xtend 
     175 
     176Where the doGenerate methode defines how the files given by a Resource and a  !IfileSystemAccess should generate a new file. While for every relevant Entity from the  
     177 
     178BNF a compile Methode handles the generation in the new file, while it calls the compile Methode for every related Entity e.g.: 
     179 
     180'''override''' '''void''' doGenerate(Resource resource, IFileSystemAccess fsa) { 
     181 
     182'''for'''(e : resource.allContents.''toIterable''.''filter''(!EtsiBnf)) { 
     183 
     184'''if'''(e.bnfEntry.size !=0) { 
     185 
     186fsa.generateFile(e.name +".fo", e.compile) 
     187 
     188} 
     189 
     190} 
     191 
     192'''def'''compile(!DefinitionList dList)!'''«'''FOR'''sDef : ist.singleDefinition»«sDef.compile» 
     193 
     194        «'''IF''' !sDef.equals(dList.singleDefinition.''last'')»|«'''ENDIF'''»«'''ENDFOR'''»!''' 
     195 
     196'''Generation of PDF using Apache FOP:''' 
     197 
     198Based 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. 
     199 
     200For this the dodoGenerateMethode needed an upgrade to access the filesystem via URIs: 
     201 
     202'''overridevoid'''doGenerate(Resource resource, IFileSystemAccess fsa) { 
     203 
     204'''var'''String workspacePath = !WorkspaceResolver.''getWorkspace''(); 
     205 
     206'''for'''(e : resource.allContents.''toIterable''.''filter''(!EtsiBnf)) { 
     207 
     208'''if'''(e.bnfEntry.size !=0) { 
     209 
     210fsa.generateFile(e.name +".__fo__", e.compile) 
     211 
     212//generate__pdf__ 
     213 
     214'''var'''uri = (fsa'''as'''IFileSystemAccessExtension2).getURI(e.name +".__fo__"); 
     215 
     216'''var'''String fullUri = workspacePath + uri.path.substring(10,                                        uri.path.length); 
     217 
     218'''var'''File file ='''new'''File(fullUri); 
     219 
     220'''if'''(file.exists) { 
     221 
     222foToPdf.''createPdfFromFo''(fullUri.substring(0, fullUri.length -3)); 
     223 
     224} 
     225 
     226} 
     227 
     228} 
     229 
     230} 
     231 
     232To 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. 
     233 
     234[[BR]]'''Formatting or Prittey Printing is to format the BNF-Document:''' 
     235 
     236In the File de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.formatting/!EbnfFormatter.xtend 
     237 
     238the Method configureFormatting(!FormattingConfig c)allows to define formatting rules 
     239 
     240before, after or between Enteties or Keywords. 
     241 
     242e.g.: 
     243 
     244@Inject'''extension'''!EbnfGrammarAccess 
     245 
     246'''overrideprotectedvoid'''configureFormatting(!FormattingConfig c) { 
     247 
     248c.setLinewrap(0,1,2).before(SL_COMMENTRule) 
     249 
     250c.setLinewrap(0,1,2).before(ML_COMMENTRule) 
     251 
     252c.setLinewrap(0,1,1).after(ML_COMMENTRule) 
     253 
     254'''var'''!EbnfGrammarAccess f = getGrammarAccess'''as'''!EbnfGrammarAccess; 
     255 
     256c.setLinewrap.before(f.ruleRule); 
     257 
     258c.setLinewrap.before(f.importRule); 
     259 
     260c.setNoSpace.after(f.ruleAccess.rulenumberINTTerminalRuleCall_0_0_0) 
     261 
     262} 
     263 
     264The Entities are recieved via  an Inector that gives access to The Grammar. 
     265 
     266[[BR]]'''Outlining and Labeling are Features, that show the document Structure of the BNF-Document:''' 
     267 
     268Outlinining can be customized in the File 
     269 
     270de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.outline/!EbnfOutlineTreeProvider.xtend. 
     271 
     272Here you can define a_createChildren()with the rootNode and the BNF-Entity of the Grammar to change the outline sequence: 
     273 
     274'''defvoid'''_createChildren(!DocumentRootNode parentNode, !EtsiBnf bnf) { 
     275 
     276createNode(parentNode,bnf); 
     277 
     278} 
     279 
     280Labeling is made to customize what the outline text for an Entity should look like. 
     281 
     282It can be customized in the file 
     283 
     284de.ugoe.cs.swe.bnftools.ebnf.ui/de.ugoe.cs.swe.bnftools.ui.labeling/!EbnfLabelProvider.xtend 
     285 
     286Where for every Entity a text can be defined: 
     287 
     288'''def'''text(!ImportSection sec){ 
     289 
     290'Imports' 
     291 
     292} 
     293 
     294[[BR]]'''File import allows to reference Rules from one BNF-Document in another:''' 
     295 
     296There are 2 ways for imports, via URI and VIA Namespaces: 
     297 
     298The BNF-Grammar uses the URI version. To Activate this the lines 
     299 
     300fragment= scoping.!ImportNamespacesScopingFragment'''auto-inject'''{} 
     301 
     302fragment= exporting.!QualifiedNamesFragment'''auto-inject'''{} 
     303 
     304fragment= builder.!BuilderIntegrationFragment'''auto-inject'''{} 
     305 
     306fragment= types.!TypesGeneratorFragment'''auto-inject'''{} 
     307 
     308in the .mwe2 file have to be commented out and the lines: 
     309 
     310fragment= scoping.ImportURIScopingFragment'''auto-inject'''{} 
     311 
     312fragment= exporting.!SimpleNamesFragment'''auto-inject'''{} 
     313 
     314must be included. 
     315 
     316After That imports can be defined like this and will automaticly be used: 
     317 
     318'import'importURI=STRING 
     319 
     320'''Also it is possible to add features to the UI via Xtext:''' 
     321 
     322In the File de.ugoe.cs.swe.bnftools.ebnf.ui/plugin.xml new extensions to the UI can be created in the plugin.xml tab. e.g.: 
     323 
     324<extension 
     325 
     326point="org.eclipse.ui.handlers"> 
     327 
     328<handler 
     329 
     330class="!de.ugoe.cs.swe.bnftools.ui.EbnfExecutableExtensionFactory:de.ugoe.cs.swe.bnftools.ui.handler.GenerationHandler" 
     331 
     332commandId="de.ugoe.cs.swe.bnftools.ui.handler.!GenerationCommand"> 
     333 
     334</handler> 
     335 
     336</extension> 
     337 
     338<extension 
     339 
     340point="org.eclipse.ui.commands"> 
     341 
     342<commandname="Generate Code" 
     343 
     344id="de.ugoe.cs.swe.bnftools.ui.handler.!GenerationCommand"> 
     345 
     346</command> 
     347 
     348</extension> 
     349 
     350<extensionpoint="org.eclipse.ui.menus"> 
     351 
     352<menuContributionlocationURI="!popup:org.eclipse.jdt.ui.PackageExplorer"> 
     353 
     354<command 
     355 
     356commandId="de.ugoe.cs.swe.bnftools.ui.handler.!GenerationCommand" 
     357 
     358style="push"> 
     359 
     360<visibleWhen 
     361 
     362checkEnabled="false"> 
     363 
     364<iterate> 
     365 
     366<adapttype="org.eclipse.core.resources.IResource"> 
     367 
     368<testproperty="org.eclipse.core.resources.name" 
     369 
     370value="*.bnf"/> 
     371 
     372</adapt> 
     373 
     374</iterate> 
     375 
     376</visibleWhen> 
     377 
     378</command> 
     379 
     380</menuContribution> 
     381 
     382</extension> 
     383 
     384This extension creates a new button in the popupmenu that opens when 
     385 
     386rightclicking a .bnf file which triggers a handlerde.ugoe.cs.swe.bnftools.ui.handler.!GenerationHandler 
     387 
     388for this File that should call the Generator of the Grammar for this File. 
     389 
     390@Override 
     391 
     392'''public'''Object execute(!ExecutionEvent event)'''throws'''!ExecutionException { 
     393 
     394ISelection selection = !HandlerUtil.''getCurrentSelection''(event); 
     395 
     396'''     if'''(selection'''instanceof'''IStructuredSelection) { 
     397 
     398IStructuredSelection structuredSelection = (IStructuredSelection)                       selection; 
     399 
     400Object firstElement = structuredSelection.getFirstElement(); 
     401 
     402'''             if'''(firstElement'''instanceof'''IFile) { 
     403 
     404IFile file = (IFile) firstElement; 
     405 
     406IProject project = file.getProject(); 
     407 
     408IFolder srcGenFolder = project.getFolder("src-gen"); 
     409 
     410'''                     if'''(!srcGenFolder.exists()) { 
     411 
     412'''                     try'''{ 
     413 
     414srcGenFolder.create('''true''','''true''','''new'''!NullProgressMonitor()); 
     415 
     416}'''catch'''(!CoreException e) { 
     417 
     418'''                             returnnull'''; 
     419 
     420} 
     421 
     422} 
     423 
     424'''             final'''!EclipseResourceFileSystemAccess2 fsa =fileAccessProvider.get(); 
     425 
     426fsa.setOutputPath(srcGenFolder.getFullPath().toString()); 
     427 
     428URI uri = URI.''createPlatformResourceURI''(file.getFullPath().toString(),'''true'''); 
     429 
     430!ResourceSet rs =resourceSetProvider.get(project); 
     431 
     432Resource r = rs.getResource(uri,'''true'''); 
     433 
     434generator.doGenerate(r, fsa); 
     435 
     436} 
     437 
     438} 
     439 
     440'''     returnnull'''; 
     441 
     442} 
     443 
     444Here is a Problem since the!EclipseResourceFileSystemAccess2does not contain all the needed inforamtion. Maybe it can be looked up in the normal call of the generator. 
     445 
     446'''Deployment as Plugin:''' 
     447 
     448If you want to deploy your the BNF Tools you can use the deployment as plugin: 
     449 
     450Rightclick 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 
     451 
     452'''Deployment as RCP: ''' 
     453 
     454If 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). 
     455 
     456First create your__xText Project__, then create a new__Plug-in Project.__Give it a name, 
     457 
     458e.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. 
     459 
     460now 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__. 
     461 
     462Now 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. 
     463 
     464Now 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__ 
     465 
     466. 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__. 
     467 
     468@ To make the generator run properly you need to add org.eclipse.xtext.xbase to your product configuration dependencies