Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » name feature not assigned with string.
name feature not assigned with string. [message #1012535] Thu, 21 February 2013 13:48 Go to next message
Mr Manner is currently offline Mr Manner
Messages: 26
Registered: January 2013
Junior Member
I have this simple json grammar, note the Generic member that has a key and a name feature:

grammar com.nuance.voconhint.Json with org.eclipse.xtext.common.Terminals

generate json "http://example.com"
Object:
	{Object} '{'
		(members+=Member)?
		(',' members+=Member)*
	'}';

Member:
	Generic | Name;

Generic:
	key=STRING ':' name=Value;

Name:
	key='\"name\"' ':' name=STRING;

Value:
	Object | STRING | Array | Boolean | Null | NUMBER;
 
Array:
	{Array} '[' (values+=Value)? (',' values+=Value)* ']';
 	
Boolean:
  'true' | 'false';
 
Null:
  'null';
 
terminal NUMBER:
	'-'? INT? '.' INT (('E'|'e') '-'? INT)?;


If I test my model with a simple json example the value of the name key for version is null:

	val jsonText1 = "{
		\"version\": \"1.0\",
		\"logger\": [\"log1\", \"log2\", \"log3\"]
	}"

    val model = parser.parse(jsonText1)


I looked up the name feature in the debugger and it is assigned to null, I would expect that the xtext parser creates the name value based on the string, why isn't it doing that? How can I force it to assign "1.0" to the name feaure of the value member?

Regards
Re: name feature not assigned with string. [message #1012539 is a reply to message #1012535] Thu, 21 February 2013 14:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6196
Registered: July 2009
Senior Member
Hi

the problem is that you mix up terminal and non terminal rules

Value:
Object | STRING | Array | Boolean | Null | NUMBER;

=> you have to take more care about object creation and feature assignment

Value:
	Object | StringValue | Array | Boolean | Null | NumberValue;
 
Array:
	{Array} '[' (values+=Value)? (',' values+=Value)* ']';
 	
Boolean:
  {Boolean} (value?='true' | 'false');
 
Null:
  {Null}'null';
  
NumberValue:
	value=NUMBER
;  

StringValue:
	value=STRING
;  
 
terminal NUMBER:
	'-'? INT? '.' INT (('E'|'e') '-'? INT)?;

Re: name feature not assigned with string. [message #1013013 is a reply to message #1012539] Fri, 22 February 2013 10:56 Go to previous message
Mr Manner is currently offline Mr Manner
Messages: 26
Registered: January 2013
Junior Member
Yes! That does the trick thx for your help.
Previous Topic:Left recursion
Next Topic:cross references and the next rule without keyword
Goto Forum:
  


Current Time: Wed Aug 20 01:09:24 EDT 2014

Powered by FUDForum. Page generated in 0.17729 seconds