Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Expression Language Formatting and Quickfixes
Expression Language Formatting and Quickfixes [message #1844371] Sat, 11 September 2021 13:06 Go to next message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 38
Registered: July 2009
Member
I am struggling with formatting a simple expression language, e.g. with a rule such as:

Primary returns Expression:
  '(' Expression ')' |
  {Not} "!" expression=Primary |
  Atomic;


How can I format the space around the parentheses? I know how to do it normally, but here we just have an "Expression" and I don't know how to target the parentheses.

Additionally, I provide a validation that detects the following expression:

!(x == 5)


I want to write a quickfix that transforms this into

x != 5


but I do not know how to get rid of the parentheses with a model based quickfix. I get:

(x != 5)


Do I really have to resort to textual manipulations?
Re: Expression Language Formatting and Quickfixes [message #1844374 is a reply to message #1844371] Sat, 11 September 2021 15:34 Go to previous messageGo to next message
Yannick DAVELUY is currently offline Yannick DAVELUYFriend
Messages: 39
Registered: July 2020
Member
Hello,
I think that you have to create a specific parenthesizedExpression object :
Primary returns Expression:
 {ParenthesizedExpression} '(' value=Expression ')' |
  {Not} "!" expression=Primary |
  Atomic;



Yannick
Re: Expression Language Formatting and Quickfixes [message #1844386 is a reply to message #1844374] Sun, 12 September 2021 14:45 Go to previous messageGo to next message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 38
Registered: July 2009
Member
I guess the question should have been: "how can I format such an expression without introducing to a dedicated parenthesized expression class".
Re: Expression Language Formatting and Quickfixes [message #1844388 is a reply to message #1844386] Sun, 12 September 2021 15:04 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you consider the text

(((x)))

which should be a legal although gratuitously bloated exposition, you have to decide whether to humour your user by faithfully respecting the bloat or to pretty print it instead. The latter is akin to corruption, particularly when redundant parentheses are used by a user/reader who may lack precise knowledge of operator precedences. Once you decide to respect the user's typing you need the ParentheszedExpression and your problem goes away; the quickfix can strip a level.

Regards

Ed Willink
Re: Expression Language Formatting and Quickfixes [message #1844393 is a reply to message #1844388] Sun, 12 September 2021 20:28 Go to previous message
Alfredo Aldundi is currently offline Alfredo AldundiFriend
Messages: 38
Registered: July 2009
Member
again, it is not about the fact that a parenthesized expression can fix the situation. The question is whether it is possible to fix the situation without such an expression.
Previous Topic:No Xtext languages have been registered
Next Topic:Configurable generator
Goto Forum:
  


Current Time: Thu Apr 25 14:22:05 GMT 2024

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

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

Back to the top