Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XTEXT How to add data to grammar(xtext)
XTEXT How to add data to grammar [message #1467614] Mon, 10 November 2014 06:54 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Let's say I have a grammar that reads all the names of the employees.

Model:
def +=employees*
;

employees:
'Employee' 'Name' '=' name=ID
'Employee' 'ID' '=' emp_id=ID
;

In my code, I want to add by default some existing employees already. Like the president, vp, etc. So I have an array of employees, declared like this:

val aEmployees = new ArrayList<employees>()


This variables contains all the configured employee names by the user. I add the configured names during the transform section.

But, when I tried to add manually a static code,
val emp = new employees()
emp.setName("chris")
emp.setEmp_id("xx123");


I am getting an error since employees is only an interface.


What are the ways to add it manually?

[Updated on: Mon, 10 November 2014 06:56]

Report message to a moderator

Re: XTEXT How to add data to grammar [message #1467624 is a reply to message #1467614] Mon, 10 November 2014 07:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not sure about your usecase (then the code shall be executed)
but in emf you use the YourDslFactory.eINSTANCE.createXXX methods to create instances of metaclasses


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XTEXT How to add data to grammar [message #1487755 is a reply to message #1467624] Wed, 26 November 2014 03:47 Go to previous message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Thank you!
Previous Topic:Textblock within ParserRule
Next Topic:How to export the smallest possible JAR file size
Goto Forum:
  


Current Time: Thu Apr 18 07:17:03 GMT 2024

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

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

Back to the top