Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » String without double quotes
String without double quotes [message #1839252] Thu, 18 March 2021 11:44 Go to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Hi all,

I am writing a grammar in which I want to be able to write a sequence of characters. I used name=STRING, but in that case I get double quotes, meaning I get the following:

"The cat is under the table"

While I want:

The cat is under the table.

Any idea on how to achieve that, or it is not possible?

Thank you,
John
Re: String without double quotes [message #1839253 is a reply to message #1839252] Thu, 18 March 2021 11:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13939
Registered: July 2009
Senior Member
One question would be: where does your staring start and where does it end.
in which context is it used.


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: String without double quotes [message #1839255 is a reply to message #1839253] Thu, 18 March 2021 12:14 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
For now the Terminal rule is

Rule:
"[" name=STRING "]" ;

So it should be in between the square brackets.
Re: String without double quotes [message #1839264 is a reply to message #1839255] Thu, 18 March 2021 12:55 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7129
Registered: July 2009
Senior Member
Hi

You want to look at your question the other way around. How do you tell the difference between an unquoted sequence of characters where you want a STRING and exactly the same sequence of characters that are meaningful elsewhere. It seems to me that your grammar must be free of all keywords and structure and so a parse amounts to no more than an ASCII copy.

Regards

Ed Willink
Re: String without double quotes [message #1839268 is a reply to message #1839264] Thu, 18 March 2021 13:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13939
Registered: July 2009
Senior Member
if you dont use [] anywhere else you could introduce a terminal

terminal MY_STRING : '[' -> ']';


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: String without double quotes [message #1839292 is a reply to message #1839268] Thu, 18 March 2021 20:45 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Hi Christian,

Can you help me with the steps required to implement that?

Where would I need to add the rule, any other file I should change? What other changes should I make in order to get autocompletion?

And what does the arrow stand for?

Thanks,
John
Re: String without double quotes [message #1839293 is a reply to message #1839292] Thu, 18 March 2021 20:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13939
Registered: July 2009
Senior Member
Add it to the grammar and use it In your rule instead of string and the keywords you have now

Rule:name=MY_STRING;
Regenerate
Adapt the complete_MY_STRING method in the proposal provider

The arrow is an up/until to operator in the Lexer

You may also want to implement a value converter (see the one for String)


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

[Updated on: Thu, 18 March 2021 20:50]

Report message to a moderator

Re: String without double quotes [message #1839325 is a reply to message #1839293] Fri, 19 March 2021 10:41 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Hi Christian,

When I open the AbstractProposalProvider, I see that my rule is there:

public void complete_UNQUOTED(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// subclasses may override
}

Would that be enough?

And can you help me find in which file is the value converter cause I cannot seem to find it.

Many thanks,
John
Re: String without double quotes [message #1839326 is a reply to message #1839325] Fri, 19 March 2021 10:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13939
Registered: July 2009
Senior Member
you need to override that and fill it with the proposals you want
e.g. acceptor.accept(createCompletionPropoals("[]", context))


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: String without double quotes [message #1839327 is a reply to message #1839325] Fri, 19 March 2021 10:46 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Hi Christian,


It works, but apparently I use those brackets somewhere else. Is there any other way to do that? To remove the quotes from the string?

Thanks

[Updated on: Fri, 19 March 2021 10:55]

Report message to a moderator

Re: String without double quotes [message #1839330 is a reply to message #1839327] Fri, 19 March 2021 10:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13939
Registered: July 2009
Senior Member
there is only the ugly solution of

// no more terminal
MY_STRING : '[' ID+ ']'; // will have problems with keywords so you might have to introduce and use MyID: ID | "keyword1" | .... | "keywordn" ; there or even add INT to it if you want to have it there and also "."
you see there is no clean solution.
maybe you can digg into external lexers but this is a complex topic.


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: String without double quotes [message #1839340 is a reply to message #1839330] Fri, 19 March 2021 12:13 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Hi Christian,

Wouldn't this approach allow me to only write ID or INT or one of the keywords?

Because another example that I might use in my grammar is:

count++;
Re: String without double quotes [message #1839343 is a reply to message #1839340] Fri, 19 March 2021 12:23 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
I tried the following approach and it works, but based on your experience, do you see issues coming up by using it this way?


SPECIAL hidden (WS,INT,ID):
('/'| '!' | '§' | '%' | '&' | '(' | ')' | '?' | '*' | '+' | '.' | '-' | '|' | ';' | '=' )+;
Re: String without double quotes [message #1839344 is a reply to message #1839343] Fri, 19 March 2021 12:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13939
Registered: July 2009
Senior Member
problem e.g. when you introduce expressions

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: String without double quotes [message #1839349 is a reply to message #1839344] Fri, 19 March 2021 13:10 Go to previous messageGo to next message
John Doe is currently offline John DoeFriend
Messages: 138
Registered: October 2020
Senior Member
Sorry, didn't quite understand what you mean by that.
What would be an example where this grammar would create issues?

Thank you,
John
Re: String without double quotes [message #1839352 is a reply to message #1839349] Fri, 19 March 2021 13:24 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13939
Registered: July 2009
Senior Member
SPECIAL hidden (WS,INT,ID):
('/'| '!' | '§' | '%' | '&' | '(' | ')' | '?' | '*' | '+' | '.' | '-' | '|' | ';' | '=' )+;
if you introduce math. expressions then having + and - here might be a problem


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
Previous Topic:Required steps to create Language Server with Maven
Next Topic:xtext build fails with JavaSE-11 and 2021-03
Goto Forum:
  


Current Time: Fri May 14 11:19:44 GMT 2021

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

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

Back to the top