Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to define Xtext grammar for a strange scenario
How to define Xtext grammar for a strange scenario [message #1793243] Thu, 02 August 2018 06:36 Go to next message
mind calm is currently offline mind calmFriend
Messages: 52
Registered: July 2017
Member
Hi,
I have a model with two types, Array and Element, the Array contains elements.

I want the dsl allow below style:
array arr1 {
    elements {
        ele1, 
        element ele3 {
            price 10 
        }
    }
}

element ele1 {
    price 8
}


It means in elements, Element entity and Element reference can be coexist. Is it possible? If it is possible, how to define the grammar?



Best regards!

by Keep Mind Calm

[Updated on: Thu, 02 August 2018 07:11]

Report message to a moderator

Re: How to define Xtext grammar for a strange scenario [message #1793245 is a reply to message #1793243] Thu, 02 August 2018 06:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
i dont understand

(list+=AbstractElement ("," list+=AbstractElement)*)?

AbstractElement: Element | ElementReference;


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to define Xtext grammar for a strange scenario [message #1793252 is a reply to message #1793245] Thu, 02 August 2018 07:53 Go to previous messageGo to next message
mind calm is currently offline mind calmFriend
Messages: 52
Registered: July 2017
Member
Hi, Christian

Sorry for i did not describe it clearly. I post my grammar and model below:

grammar org.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate myDsl "http://www.mydsl.org/MyDsl"

Model:
	greetings+=AbstractElement*;

AbstractElement:
	Array | Element
;

Array:
	'array' name=ID '{'
		'elements' '{' (elements+=[Element|EString] ("," elements+=[Element|EString])*)? '}'
	'}';

Element:
	'element' name=ID '{'
		'price' price=EInt
	'}'
;

EInt returns ecore::EInt:
	'-'? INT;

EString returns ecore::EString:
	STRING | ID;



array arr1 {
	elements {
		ele1,
		element ele2 {
			price 2
		}
	}
}

element ele1 {
	price 5
}


There will have errors at line "element ele2 {" in Xtext editor.

From your reply, do you mean we define a type ElementReference? but i just want use the attribute name as reference of Element, is it possible?


Best regards!

by Keep Mind Calm

[Updated on: Thu, 02 August 2018 07:55]

Report message to a moderator

Re: How to define Xtext grammar for a strange scenario [message #1793253 is a reply to message #1793252] Thu, 02 August 2018 07:56 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
i thought that was clear:

ElementReference: element=[Element|EString];


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Display EXPENSIVE checks when building
Next Topic:Using Keywords as Identifiers
Goto Forum:
  


Current Time: Thu Sep 20 06:28:10 GMT 2018

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

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

Back to the top