Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using WS as delimiter in part of grammar
Using WS as delimiter in part of grammar [message #1794563] Mon, 03 September 2018 06:49 Go to next message
Weihua Fan is currently offline Weihua FanFriend
Messages: 18
Registered: December 2015
Junior Member
We have an expression like grammar, simplified as following:
MainRule:
	'{' 'MAIN'? main=Pattern '}' ';'?
;

Pattern : 
	Concat
;

Concat returns Pattern :
	Union ({Concat.left=current} right=Union)*
;

Union returns Pattern:
	And ({Union.left=current} '|' right=And)* 
;

And returns Pattern:
	Primary ({And.left=current} '&' right=Primary)*
;

Primary returns Pattern
	:  {Optional} '(' pattern=Concat ')'
	|  {Multi} '{' pattern=Concat '}'
	|  {Not} '!' pattern=Primary 
	|  {Atomic} pattern=Atomic
    ;

Atomic returns Pattern
	:  {Word} value=STRING
	|  {Feature} value=ID
;


as you can see we use WS as delimiter in rule Concat.
Our language users report that they often miss type "&" or "|" between words and/or features, but xtext wont report any error.
FeatureA"someword"   // what they typed and no error

FeatureA&"someword"   // what they should type

FeatureA  "someword"  // xtext parsed as Concat


I've tried to override the global hidden() on Concat rule(hidden(ML_COMMENT, SL_COMMENT)), make WS not hidden, but it seems all following rules are WS sensitive, thats not what i want.

Is there a way to make only Concat rule WS sensitive?
Or any other way to solve this problem?
Re: Using WS as delimiter in part of grammar [message #1794569 is a reply to message #1794563] Mon, 03 September 2018 07:43 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6037
Registered: July 2009
Senior Member
Hi

In your language

Word Word Word Word

is a valid concatenation.

If you really want to use WS as a concatenation operator, you must specify it explicitly as the only way to concatenate and prohibit its implicit use everywhere else.

However since you have already demonstrated that this is difficult to program and use, I strongly suggest you review your design decision to use WS as anything more than a separator. Ultimately your users are going to be confused by a non-standard language even if you get the tooling to work.

Regards

Ed Willink
Re: Using WS as delimiter in part of grammar [message #1794618 is a reply to message #1794569] Tue, 04 September 2018 04:20 Go to previous message
Weihua Fan is currently offline Weihua FanFriend
Messages: 18
Registered: December 2015
Junior Member
Thanks for the reply.
Previous Topic:Usage of IContextualOutputConfigurationProvider(2)
Next Topic:Generation based on DSL files in classpath
Goto Forum:
  


Current Time: Thu Sep 20 23:48:01 GMT 2018

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

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

Back to the top