2/5 Defining a Domain Specific Language (DSL) using XText in Eclipse

Hi. I’m Paul Wells from AgileJ in a previous video we saw an overview
of the benefits of using XText to define your domain specific language in this video we’re gonna actually go ahead and
see how we can use XText to make a new project and I’ll show you how to start making
your own DSL right, well the first thing we have to do is great the projects so righ click in the package explorer new other Xtext Xtext project and we give it a name so I’ll call it com AgileJ demo and up here it tells me that I’ve got to match the project
name to the language name so that’s com AgileJ demo demo language and I’ll give the language the name demo DSL and I will give… any file… this is the extension that
will be applied to any files which are made with this language name and it’s worth taking time to get these right er.. the generator – we’re not going to be
using this time press finish and then… there we go
so it’s made two new projects one is the user interface project and one is the language project and it’s opened for us a new file called DemoDsl.xtext
and this is where we define our grammar the file that was opened is an example grammar what I’m going to do now is I’m going to actually compile it, so this is the xtext file. Any dot xtext file is a grammar definition, and as was generated for us just now next to the xtext file is the MWE file, and if you right click on that and select ‘run as’ you have this option here MWE workflow slect that and it will crunch away for a minute now if we look at the console we can see that
we’ve got this message here saying workflow completed in fifteen seconds the next thing
we what to do is to run it and we do that by selecting in the user interface
project the plugin.xml file that opens in an editor and down here
we have the option of testing launch an Eclipse application and we let that start up
now we have a new empty workspace inside here we need a new project let’s just call it test and inside here we need to make a file and we’ll call that test.ddsl
remember DDSL is the file name extension that we nominated when you ran the wizard and then inside here we should have a… a working editor, and we do. so let’s select that – space and then control space again it’s prompting for a URI let’s just give it this one here okay …and what else does it want? select type and it wants an ID so lets call it
Fred. OK. save that. it’s happy there are no problems no errors so now we’ve seen it run end to end what I’ve done is I’ve commented out the last
part of the default grammar which xtext gave us and I’ve added and new component called ‘hello world’ which is literally just the string hello world and I’ve changed the model to be just one of these hello world components. so you need to compile the grammar again so run as MWE workflow and save it. yes that’s now completed so we go back to the plugin tab launch Eclipse application and now, well this file which didn’t have any errors now does have errors the reason for that being that we’ve changed
the grammar underneath it so we can delete that line and replace it with… hello world and now that’s legal. so we’ve now defined our own grammar and seen it checked for problems by the new editor that we generated.

Leave a Reply

Your email address will not be published. Required fields are marked *