How to create an XML schema for my grammar [message #1516260] |
Thu, 18 December 2014 19:26 |
cande gut Messages: 5 Registered: December 2014 |
Junior Member |
|
|
Hi,
I am new to Xtext/Xtend and I would like to know how can I create a code generator for my code built with my grammar, so that is then written my code in an XML. I have been searching on web for days and can figure out what they say, since everything is about Xtend and the IGenerator, but I am a beginner and I would really appreciate any help, thank you.
[Updated on: Thu, 18 December 2014 19:26] Report message to a moderator
|
|
|
Re: How to create an XML schema for my grammar [message #1516271 is a reply to message #1516260] |
Thu, 18 December 2014 19:36 |
|
Hi am not sure what you exaclty want to do. can you show an example grammar and an expected output xml.
generating xml is the same as generating text.
have a look at the hello world example that is created by the xtext wizard.
the generator looks like
class MyDslGenerator implements IGenerator {
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
fsa.generateFile('greetings.txt', 'People to greet: ' +
resource.allContents
.filter(typeof(Greeting))
.map[name]
.join(', '))
}
}
it should be easy to change that to
class MyDslGenerator implements IGenerator {
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
val model = resource.contents.head as Model
fsa.generateFile('greetings.xml', '''
<model>
«FOR g : model.greetings»
<greeting>«g.name»</greeting>
«ENDFOR»
</model>
''')
}
}
i strongly recommend you to do the xtext tutorial and the xtend tutorial.
if this does not answer your question please ask more specific (with code example)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.03406 seconds