Skip to main content



      Home
Home » Modeling » TMF (Xtext) » White Spaces into keywords of Xtext grammar(the possibility of inserting white spaces into Xtext keywords grammar)
White Spaces into keywords of Xtext grammar [message #671372] Tue, 17 May 2011 12:29 Go to next message
Eclipse UserFriend
Hi All,

I have a question regarding using white spaces into Xtext
grammar syntax, for example:

ValidationRuleDef : 'Validation Rule' name = QuotedID

is it possible?, because, in my grammar, we have a plenty of key words,
also what are the issues that can be raised during the parsing because of that?,
as i remember one of the Xtext group experts, warned me from using white spaces
into the keywords!

Thanks a lot for your support,

Re: White Spaces into keywords of Xtext grammar [message #671380 is a reply to message #671372] Tue, 17 May 2011 12:51 Go to previous messageGo to next message
Eclipse UserFriend
You don't necessarily have to set WS as hidden for the whole grammar.
You can apply it to specific rules only.

ValidationRuleDef: 'Validation Rule' ValidationRuleValue;
ValidationRuleValue
hidden (WS): name=QuotedID;

Note: WS will be hidden for all subrules of ValidationRuleValue.

I've made the assumption that, for your grammar, 'Validation Rule' must contain only one space.

[Updated on: Tue, 17 May 2011 12:54] by Moderator

Re: White Spaces into keywords of Xtext grammar [message #671399 is a reply to message #671372] Tue, 17 May 2011 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Is the single space significant or is input valid if you have
"Validation" and "Rule" separated by two spaces?

I would simply do like this

ValidationRuleDef : 'Validation' 'Rule' name = QuotedID ;

If you really need to flag anything but a single space between the two
keywords as an error, you can do so in validation.

You want to be as forgiving as possible in your grammar and use
validation to capture errors in the input as this makes it possible to
both provide meaningful error messages as well as quick fix codes. When
it is only determined by grammar the user typically just gets "syntax
error".

If you really want a single space, and really want it in the grammar,
you could try something like:

ValidationRuleDef : ValidationRuleKw name = QuotedID ;
ValidationRuleKw hidden() : 'Validation' ' ' 'Rule' ;

or, it may work with:
ValidationRuleKw hidden() : 'Validation Rule' ;

- henrik

On 5/17/11 6:29 PM, romeh wrote:
> Hi All,
>
> I have a question regarding using white spaces into Xtext
> grammar syntax, for example:
>
> ValidationRuleDef : 'Validation Rule' name = QuotedID
>
> is it possible?, because, in my grammar, we have a plenty of
> key words,
> also what are the issues that can be raised during the
> parsing because of that?,
> as i remember one of the Xtext group experts, warned me from
> using white spaces into the keywords!
>
> Thanks a lot for your support,
>
>
Re: White Spaces into keywords of Xtext grammar [message #671506 is a reply to message #671399] Wed, 18 May 2011 03:21 Go to previous message
Eclipse UserFriend
Hi,

the main problem with spaces in keywords is that the tokeniser is greedy (trying tokens to be as long as possible). Assume you have a keyword "is OK" in your languange (e.g. for setting some boolean flag). Basically that implies that you cannot use "is" anywhere else in the language, because whenever you write "is" followed by a single white space, the "is OK"-token is expected, hence you will get an error on "is really nice" saying that "r" is an illegal input as "O" is expected (try to explain that error message to a user).

So in your case (which may not really bother you, but it is still considered bad style - at least by me), you will not be able to use "Validation" anywhere else in the language (and there are errors if you put two spaces before Rule).

Alex

P.S.: It is not a problem if there are many keywords in the grammar. You may well split (what you consider) one keyword into two.

RuleX: 'Validation' 'Rule' ...;
RuleY: 'Action' 'Rule' ...;

is perfectly OK. Xtext has no problem distinguishing by a sequence of keywords rather than a single one.

[Updated on: Wed, 18 May 2011 03:24] by Moderator

Previous Topic:[Xtext] Problem : Cannot find compatible feature foo in sealed EClass
Next Topic:Configuring mwe2 file of Xpand .generator project when having imported metamodel in Xtext
Goto Forum:
  


Current Time: Fri Jul 04 11:55:27 EDT 2025

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

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

Back to the top