Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to create an XML schema for my grammar
How to create an XML schema for my grammar [message #1516260] Thu, 18 December 2014 19:26 Go to next message
cande gut is currently offline cande gutFriend
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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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
Re: How to create an XML schema for my grammar [message #1516361 is a reply to message #1516260] Thu, 18 December 2014 21:02 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your question does not really make sense, since you do not normally
represent grammars with XSD. Grammars use BNF/EBNF. An Xtext grammar is
really just an annotated EBNF and stripping the annotations is a simple
transformation.

Perhaps you want an XSD for the associated metamodel, in which case you
just set the generate schema option in the genmodel file.

Regards

Ed Willink


On 18/12/2014 19:26, cande gut wrote:
> 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.
Previous Topic:Xtext
Next Topic:Scope & Type Hierarchy
Goto Forum:
  


Current Time: Fri Apr 26 15:44:30 GMT 2024

Powered by FUDForum. Page generated in 0.03406 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top