Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to add default value to a grammar rule
How to add default value to a grammar rule [message #1069090] Mon, 15 July 2013 06:37 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I have this grammar:

config:
'config' name=ID 'and' value=INT
;


In my xtend code, I want to add an entry with "empty" name and "0" value.

def addEntry()
{
  var config first;
  first.name = "empty";
  first.value = "0";
  aConfigarray.add(0, first);
}


But when I look at the java implementation, it is setting the variable "first" to null, so I will get a NullPointerException upon setting the name to "empty".

Do you know how to set the name or value?
Re: How to add default value to a grammar rule [message #1069095 is a reply to message #1069090] Mon, 15 July 2013 06:46 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

you just declare the variable "first", but you don't actually create a new config. Setting name and value is OK as it is.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: How to add default value to a grammar rule [message #1069996 is a reply to message #1069095] Wed, 17 July 2013 03:30 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
How do I create a new config?

Error Couldn't resolve reference to JvmConstructor 'config' if I put it this way:
 var config = new config() 

Do you have some sample code that implements such scenario? I tried doing it differently, but I still get a java.lang.NullPointerException.

def addEntry()
{
  var config first;
  aConfigarray.add(0, first);
  aConfigarray.get(0).setName("empty");
  aConfigarray.get(0).setValue(0);
}

[Updated on: Wed, 17 July 2013 03:34]

Report message to a moderator

Re: How to add default value to a grammar rule [message #1070039 is a reply to message #1069996] Wed, 17 July 2013 06:14 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Use the factory generated for your Language.

something like

var config=MydslFactory::eINSTNANCE.createConfig

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: How to add default value to a grammar rule [message #1070542 is a reply to message #1069090] Thu, 18 July 2013 07:21 Go to previous message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
It works. Thanks, man!
Previous Topic:Content assist for Identifier
Next Topic:Terminals ambiguity
Goto Forum:
  


Current Time: Fri Mar 29 08:14:31 GMT 2024

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

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

Back to the top