Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » The ?= operator
The ?= operator [message #1790412] Sat, 09 June 2018 22:16 Go to next message
Alexandros Karypidis is currently offline Alexandros KarypidisFriend
Messages: 97
Registered: March 2010
Member
Hello,

In this grammar:

MessageSchema:
    schema=SchemaDeclaration
    types=TypeDeclarations
;

SchemaDeclaration:
    'schema' name=QName 'id' '=' id=INT 'version' '=' version=INT optionalAttrs=OptionalSchemaAttrs?;

OptionalSchemaAttrs:
    ('headerType' '=' headerType=QName)? (bigEndian ?= 'bigEndian');

TypeDeclarations:
    'types' '{' simpleTypes+=SimpleTypeDeclaration+ '}';


I want to allow for 2 optional items to the schema declaration, which I have put in rule OptionalSchemaAttrs: a header type and a switch for flipping to big endian (default is little).

The result is not exactly what I want: if I don't include header type, the presence/absence of keyword 'bigEndian' works as expected:

// this is ok:
schema org.sbelang.examples.v2.ExampleSchema 
	id = 1 version = 1 

// this is also ok:
schema org.sbelang.examples.v2.ExampleSchema 
	id = 1 version = 1 bigEndian


But if I include a header type, the keyword 'bigEndian' becomes mandatory:

// this is ok:
schema org.sbelang.examples.v2.ExampleSchema 
	id = 1 version = 1 
 	headerType = a.b.c.D
	bigEndian

types {
//...

// this is NOT ok:
schema org.sbelang.examples.v2.ExampleSchema 
	id = 1 version = 1 
 	headerType = a.b.c.D

types {
//...


The last example gives gives me the error: missing 'bigEndian' at 'types'.

According to the docs:

Quote:

The ?= sign (boolean assignment operator) expects a feature of type EBoolean and sets it to true if the right hand side was consumed, independently from the concrete value of the right hand side.


I don't understand how the presence of headerType affects the requirement for keyword 'bigEndian' to be consumed after it?
Re: The ?= operator [message #1790413 is a reply to message #1790412] Sun, 10 June 2018 04:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
?= only says. Assign the left hand side Boolean attribute with true if the righthand side is present.

=> you grammar is wrong

The usual pattern is

Myflag?="mykw"?


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: The ?= operator [message #1790416 is a reply to message #1790413] Sun, 10 June 2018 07:43 Go to previous messageGo to next message
Alexandros Karypidis is currently offline Alexandros KarypidisFriend
Messages: 97
Registered: March 2010
Member
Ok, I must say that even now looking at the docs, this was not apparent to me. Thanks you.
Re: The ?= operator [message #1790420 is a reply to message #1790413] Sun, 10 June 2018 09:41 Go to previous messageGo to next message
Alexandros Karypidis is currently offline Alexandros KarypidisFriend
Messages: 97
Registered: March 2010
Member
I've understood the issue and fixed it, but I still can't wrap my head around the fact that the right hand side must explicitly be made optional (like you pointed out, I was assuming it implicitly is).

So what is the use case for not making the right hand side optional? Can you give me an example grammar where ?= would assign false (when the right hand side is NOT optional)? Or is it practically useless, but just the way things are?

I'm just trying to make sure I understand the utility scope of this operator.
Re: The ?= operator [message #1790422 is a reply to message #1790420] Sun, 10 June 2018 10:41 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
Think of this grammar snippet


Flag?="true" |"false"


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext Serialization: how to benchmark?
Next Topic:Working with INT optional features - default value feature
Goto Forum:
  


Current Time: Wed Sep 19 19:32:30 GMT 2018

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

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

Back to the top