|
Re: Grammar help with white spaces [message #553852 is a reply to message #553826] |
Thu, 19 August 2010 07:22 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
Hi,
try the following
grammar org.xtext.example.mydsl.MyDsl with
org.eclipse.xtext.common.Terminals hidden(ML_COMMENT,SL_COMMENT,WS,NL)
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
story=Story;
Story:
"As" "a" actor=StringWithOutQuotes
"I" "want" "to" want=StringWithOutQuotes
"So" "that" that=StringWithOutQuotes;
StringWithOutQuotes hidden(): (WS|ID|INT|STRING|ANY_OTHER|"I")+;
terminal WS: (' '|'\t')+;
terminal NL: ('\r'|'\n')+;
The idea is to split new line and white space definition, so that they
can be distinguished. By default, comments new lines and white spaces
are hidden. The StringWithoutQuotes definition wants to see all tokens
(hence hidden() = none hidden). And it allows all terminal rules except
comments and new lines. The problem is that you also have to include all
keywords you want to allow in the list.
Note, keywords containing spaces cause problems. If you want better code
completion use a template with variables for the whole story.
(As a <variableOne>
I want <variableTwo>
So that <variableThree>)
You will have to adapt the highlighting, as keywords are keywords
wherever they appear, that is also within a StringWithoutQuotes.
Alex
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04135 seconds