Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Redundant usage of =current
Redundant usage of =current [message #1835352] Tue, 01 December 2020 12:18 Go to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7268
Registered: July 2009
Senior Member
Hi

The Xtext grammar contains

AssignableAlternatives returns AbstractElement:
    AssignableTerminal ({Alternatives.elements+=current} ('|' elements+=AssignableTerminal)+)?
;


Is there any advantage to this obscure non-EBNF-like form compared to the regular

AssignableAlternatives returns AbstractElement:
    AssignableTerminal  
|   {Alternatives} elements+=AssignableTerminal ('|' elements+=AssignableTerminal)+
;


More generally is there any example of

... X ... {Y.f=current ...)? ...


that cannot be more readably rewritten as

... X ...  ...
| {Y} ... ... f=X ... ...


https://bugs.eclipse.org/bugs/show_bug.cgi?id=565093#c3 files this as an Xtext enhancement.

Regards

Ed Willink
Re: Redundant usage of =current [message #1835353 is a reply to message #1835352] Tue, 01 December 2020 12:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14067
Registered: July 2009
Senior Member
as the

{Alternatives.elements+=current}

rewrites the ast/tree and

elements+=AssignableTerminal

does not, they do not do the same.

e.g. for mathematical expressions
https://www.eclipse.org/Xtext/documentation/307_special_languages.html#expressions

the rewrite will give you proper trees that care about precedences


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Redundant usage of =current [message #1835368 is a reply to message #1835353] Tue, 01 December 2020 19:44 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7268
Registered: July 2009
Senior Member
Hi

Yes, but it only rewrites because it was parsed wrongly. By not using current, the correct AST is parsed directly. In both cases the net result is a single AssignableTerminal else an Alternatives with two or more AssignableTerminal elements .

Regards

Ed Willink
Re: Redundant usage of =current [message #1835389 is a reply to message #1835368] Wed, 02 December 2020 09:08 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7268
Registered: July 2009
Senior Member
Hi

As pointed out by Sebastian on https://bugs.eclipse.org/bugs/show_bug.cgi?id=565093 , the real reason is that the rewrite is left-recursive and Xtext/ANTLR does not support left recursion. current= is an effective trick. It would be nice if it was hidden.

Regards

Ed Willink
Previous Topic:Define a limited string consisting out of figures/digits only
Next Topic:Join two scopes
Goto Forum:
  


Current Time: Mon Sep 27 08:12:15 GMT 2021

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

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

Back to the top