Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Nested Expressions / Recursion(How to build XText grammar for key/value pairs)
Nested Expressions / Recursion [message #1693207] Wed, 22 April 2015 12:10 Go to next message
Patrick Neubauer is currently offline Patrick NeubauerFriend
Messages: 8
Registered: December 2014
Junior Member
Hi,

I am wondering how to build nested expressions for key/value pairs using Xtext grammar.

The blog entry from Sven Efftige shows the idea:
http://blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html

However, what I am trying to come up with is to represent instances such as:
"key1" : "value1" (
  "key11" : "value11"
  "key12" : "value12" (
    "key121" : "value121"
  )
  "key13" : "value13"
)


The Xtext grammar, which obviously is not completely correct is as follows:
Primary returns Expression:
	(STRING ':' STRING) | '(' Child ')'
;

Child returns Expression:
	Primary ({Child.left=current} '(' right=Primary)*
;


Cheers, Patrick
Re: Nested Expressions / Recursion [message #1693209 is a reply to message #1693207] Wed, 22 April 2015 12:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

how shall the object tree look like

where shall the () be put too. on the same level as the pair before?
or does it ( optionally) belong to the values?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Nested Expressions / Recursion [message #1693210 is a reply to message #1693209] Wed, 22 April 2015 12:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
a very naive approach works fine btw

Model:
elements+=Element+;

Element:
Pair | Pairs
;

Pair:
key=STRING ":" value=STRING
;

Pairs:
{Pairs}"(" elements+=Element* ")"
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Nested Expressions / Recursion [message #1693216 is a reply to message #1693210] Wed, 22 April 2015 12:53 Go to previous message
Patrick Neubauer is currently offline Patrick NeubauerFriend
Messages: 8
Registered: December 2014
Junior Member
Dear Christian,

Thank you very much for your fast reply!
Using your grammar I can successfully build the stated example.

Well, what I am trying to do is to come up with a construct to represent a feature map.
When transforming an XML Schema to Genmodel + Ecore and then generate an Xtext project from the Genmodel it does not create a construct for EFeatureMapEntry (original creation caused by xsd:complexType mixed="true" in the XSD).

Cheers, Patrick
Previous Topic:OperationCanceledException while running MWE2 Workflow
Next Topic:how to format xtext resource on save
Goto Forum:
  


Current Time: Fri Apr 26 21:28:52 GMT 2024

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

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

Back to the top