Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » JSON Grammar(CA suggests comma although there is no element in the json object)
JSON Grammar [message #1555333] Fri, 09 January 2015 19:12 Go to next message
Luis De Bello is currently offline Luis De BelloFriend
Messages: 95
Registered: January 2015
Member
Hi guys,

I am trying to create a simple json grammar but I am having some issues with the CA when the json is empty.

Grammar:

Document:
elements+=Object+;

Object:
"{" (elements+=KeyValuePair)? ("," elements+=KeyValuePair)* "}";

KeyValuePair:
key=STRING ":" value=STRING;

---------------------------------------------
Input in the editor:

{

}

In this scenario the CA suggests me two options "," and "}", I would like to know if there is any mistake in my grammar or how I can avoid this situation;I can modify the CA logic to handle this case in a different way but I am sure that there must be a good way of writing this grammar to avoid this side effect.

Thanks in advance

Luis
Re: JSON Grammar [message #1555353 is a reply to message #1555333] Fri, 09 January 2015 19:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi, i actually cannot reproduce that.
which xtext version to you use?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JSON Grammar [message #1555360 is a reply to message #1555353] Fri, 09 January 2015 19:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
btw the comma is correct,

maybe you actually want to do the following


Object:
{Object}"{" (elements+=KeyValuePair ("," elements+=KeyValuePair)*)? "}";


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: JSON Grammar [message #1555538 is a reply to message #1555360] Fri, 09 January 2015 21:54 Go to previous messageGo to next message
Luis De Bello is currently offline Luis De BelloFriend
Messages: 95
Registered: January 2015
Member
Hi Christian,

Thanks for the answer, I am using Xtext the latest version.

You grammar is better because I can have empty objects and the comma is suggested after having one element Smile Thanks a lot. Anyway the CA continues suggesting "}" when the cursor is inside the object, any idea about that?

Regards,
- Luis
Re: JSON Grammar [message #1555583 is a reply to message #1555538] Fri, 09 January 2015 22:28 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
that is intended, it does not look at the part beyond the cusor

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Still pending] [Xtext 2.7.3] : It sounds like a bug
Next Topic:[XBase] Overriding OpAnd/OpOr rules
Goto Forum:
  


Current Time: Fri Apr 19 18:40:40 GMT 2024

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

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

Back to the top