Changes between Version 1 and Version 2 of Developer
- Timestamp:
- 06/25/14 10:19:13 (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Developer
v1 v2 5 5 '''The used Features are:''' 6 6 7 8 7 * Grammardefinition 9 8 10 11 12 13 9 * Validation 14 10 15 16 11 * Quickfixing 17 12 18 19 13 * Generation of content from the BNF 20 14 21 22 15 * Formatting 23 16 24 25 17 * Outlining 26 18 27 28 19 * File import 29 20 30 31 21 * Deployment as Plugin 32 22 33 34 23 * Deployment as RCP (Rich Client Platform) 35 24 36 37 38 25 '''Grammardefinition:''' 39 26 … … 46 33 !EtsiBnf: 47 34 48 'grammar'name=ID49 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 )35 'grammar'name=ID 36 37 ( type='/__bnf__'?';' 38 39 (importSection=!ImportSection)? 40 41 (bnfEntry+=!BnfEntry)+ 42 43 ) 44 45 | 46 47 ( type='/delta'';' 48 49 (importSection=!ImportSection)? 50 51 (deltaEntry+=!DeltaEntry)* 52 53 ) 54 55 | 56 57 ( type='/merge'';' 58 59 (importSection=!ImportSection)? 60 61 (mergeEntry+=!MergeEntry)* 62 63 ) 77 64 78 65 ; … … 80 67 To turn this into a runable application the .mwe2 file in the same folder must be executed as MWE2 Workflow. 81 68 82 After this the whole project can be executed as an Eclipse Application for testing 69 After this the whole project can be executed as an Eclipse Application for testing: 83 70 84 71 '''Validation allows to check for conditions in the BNF-Document:''' … … 92 79 '''defvoid'''checkUnusedRule(Rule rule) { 93 80 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))81 ''' var''' List<!RuleReference > references = !EbnfAnalysisUtils .'' findReferences'' (rule); 82 83 ''' var''' List<Rule> references1 = !EbnfAnalysisUtils .'' findReferences'' (rule,resourceDescriptions); 84 85 ''' if''' ((references.size+references1.size ==0) && (rule.getRulenumber() !=1)) 99 86 100 87 warning(''unusedRuleDescription'', !EbnfPackage$Literals::''RULE!__NAME'',''unusedRuleDescription'', rule.name); … … 128 115 @Fix(!EbnfValidator.''unusedRuleDescription'') 129 116 130 '''defvoid'''fixUnusedRule(Issue issue, !IssueResolutionAcceptor acceptor) { 131 132 acceptor.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 146 xtextDocument.replace(offset, textLength,""); 147 148 ]) 149 150 } 151 152 The @Fix(''String token'') annotation definies that the following method is a quickfix for a validationwarning, with that ''token'' as code parameter: 153 154 warning(''unusedRuleDescription'', !EbnfPackage$Literals::''RULE!__NAME'', ''__unusedRuleDescription__'', rule.name); 117 ''' defvoid'''fixUnusedRule(Issue issue, !IssueResolutionAcceptor acceptor) { 118 119 acceptor.accept(issue,"Remove unused rule","Delete the unused rule", 120 121 "upcase.png",[ element, context | 122 123 ''' var''' Rule rule = element''' as''' Rule; 124 125 ''' var''' IXtextDocument xtextDocument = context.getXtextDocument(); 126 127 ''' var''' ICompositeNode node = !NodeModelUtils .'' findActualNodeFor'' (rule); 128 129 ''' varint''' offset = node.textRegion.offset; 130 131 ''' var''' String nodeText = node.text; 132 133 ''' varint''' textLength = nodeText.length -2; 134 135 xtextDocument.replace(offset, textLength,""); 136 137 ]) 138 139 } 140 141 The@Fix(''String token'')annotation definies that the following method is a quickfix for a validationwarning, with that''token''as code parameter: 142 143 warning(''unusedRuleDescription'', !EbnfPackage$Literals::''RULE!__NAME'', ''__unusedRuleDescription__'', rule.name); 155 144 156 145 @Fix(!EbnfValidator.''__unusedRuleDescription__'') … … 158 147 The accaptor inside applies the changes, via two possible ways: 159 148 160 161 149 1. Change the Document itself (like the example shows). 162 150 163 164 151 1. Change the underlying ecoremodel. 165 152 166 167 168 153 [[BR]]'''Generation allows to generate other files from a BNF-Document:''' 169 154 … … 174 159 It can be customized in the File de.ugoe.cs.swe.bnftools.ebnf/de.ugoe.cs.swe.ebnf.generator/!EbnfGenerator.xtend 175 160 176 Where 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 178 BNF a compile Methode handles the generation in the new file, while it calls the compile Methode for every related Entity e.g.: 161 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 162 163 BNF a 164 165 compile 166 167 Methode handles the generation in the new file, while it calls the compile Methode for every related Entity e.g.: 179 168 180 169 '''override''' '''void''' doGenerate(Resource resource, IFileSystemAccess fsa) { 181 170 171 ''' for''' (e : resource.allContents.'' toIterable'' .'' filter'' (!EtsiBnf )) { 172 173 ''' if''' (e.bnfEntry.size !=0) { 174 175 fsa.generateFile(e.name +".fo", e.compile) 176 177 } 178 179 } 180 181 } 182 183 '''def'''compile(!DefinitionList dList)!'''«'''FOR'''sDef : ist.singleDefinition»«sDef.compile» «'''IF''' !sDef.equals(dList.singleDefinition.''last'')»|«'''ENDIF'''»«'''ENDFOR'''»!''' 184 185 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. 186 187 For this the dodoGenerateMethode needed an upgrade to access the filesystem via URIs: 188 189 '''overridevoid'''doGenerate(Resource resource, IFileSystemAccess fsa) { 190 191 '''var'''String workspacePath = !WorkspaceResolver.''getWorkspace''(); 192 182 193 '''for'''(e : resource.allContents.''toIterable''.''filter''(!EtsiBnf)) { 183 194 184 195 '''if'''(e.bnfEntry.size !=0) { 185 196 186 fsa.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 198 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.199 200 For 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 210 197 fsa.generateFile(e.name +".__fo__", e.compile) 211 198 … … 214 201 '''var'''uri = (fsa'''as'''IFileSystemAccessExtension2).getURI(e.name +".__fo__"); 215 202 216 '''var'''String fullUri = workspacePath + uri.path.substring(10, 203 '''var'''String fullUri = workspacePath + uri.path.substring(10, uri.path.length); 217 204 218 205 '''var'''File file ='''new'''File(fullUri); … … 394 381 ISelection selection = !HandlerUtil.''getCurrentSelection''(event); 395 382 396 ''' 397 398 IStructuredSelection structuredSelection = (IStructuredSelection) 383 ''' if'''(selection'''instanceof'''IStructuredSelection) { 384 385 IStructuredSelection structuredSelection = (IStructuredSelection) selection; 399 386 400 387 Object firstElement = structuredSelection.getFirstElement(); 401 388 402 ''' 389 ''' if'''(firstElement'''instanceof'''IFile) { 403 390 404 391 IFile file = (IFile) firstElement; … … 408 395 IFolder srcGenFolder = project.getFolder("src-gen"); 409 396 410 ''' 411 412 ''' 397 ''' if'''(!srcGenFolder.exists()) { 398 399 ''' try'''{ 413 400 414 401 srcGenFolder.create('''true''','''true''','''new'''!NullProgressMonitor()); … … 416 403 }'''catch'''(!CoreException e) { 417 404 418 ''' 419 420 } 421 422 } 423 424 ''' 405 ''' returnnull'''; 406 407 } 408 409 } 410 411 ''' final'''!EclipseResourceFileSystemAccess2 fsa =fileAccessProvider.get(); 425 412 426 413 fsa.setOutputPath(srcGenFolder.getFullPath().toString()); … … 438 425 } 439 426 440 ''' 427 ''' returnnull'''; 441 428 442 429 }