Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Issue with white space, optional rules, and serialization(Issue with white space, optional rules, and serialization)
Issue with white space, optional rules, and serialization [message #648441] Wed, 12 January 2011 22:50 Go to next message
Jeff  is currently offline Jeff Friend
Messages: 8
Registered: February 2010
Junior Member
Hello,
I have and issue with serializing a model with optional rule calls and redefining the WS terminal. Basically the space between keywords is not put in when a change is made to the model when one of the options is set.

Given the grammer snippet below:
"Hello where test"
gets changed to
"HelloWHERE test"

Model:
greetings+=Greeting*
types+=SimpleType*
;

Greeting:
'Hello' (
('=' '(' ('CONDITION' | 'COND') '=' condition=QualifiedName ')') |
('WHERE' compoundExpression=QualifiedName)
) ;

QualifiedName :
ID ('.' ID)*;

SimpleType:
'type'( only?= 'ONLY')? name=ID;

terminal SPACE : ' '|'\t';
terminal WS : ('\\'(SPACE|'\r'|'\n')+) | (SPACE|'\r'|'\n')+ ;


Note:
The reason this is done is our legacy language allows for unquoted file names with spaces. Is there a better way to achieve this?

Thank you,
-Jeff
Re: Issue with white space, optional rules, and serialization [message #648448 is a reply to message #648441] Wed, 12 January 2011 23:02 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Jeff,

did you customize the formatting settings for your language? You could
try to force the formatter to insert spaces between the Hello and WHERE
keywords if they appear next to each other.

Could you please file a ticket with a reproducable sample attached. This
would make sure that the issue doesn't get lost.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 12.01.11 23:50, schrieb Jeff:
> Hello,
> I have and issue with serializing a model with optional rule calls and
> redefining the WS terminal. Basically the space between keywords is not
> put in when a change is made to the model when one of the options is set.
>
> Given the grammer snippet below:
> "Hello where test"
> gets changed to
> "HelloWHERE test"
>
> Model: greetings+=Greeting*
> types+=SimpleType*
> ;
>
> Greeting:
> 'Hello' (
> ('=' '(' ('CONDITION' | 'COND') '=' condition=QualifiedName ')') |
> ('WHERE' compoundExpression=QualifiedName)
> ) ;
>
> QualifiedName :
> ID ('.' ID)*;
>
> SimpleType:
> 'type'( only?= 'ONLY')? name=ID;
>
> terminal SPACE : ' '|'\t';
> terminal WS : ('\\'(SPACE|'\r'|'\n')+) | (SPACE|'\r'|'\n')+ ;
>
>
> Note:
> The reason this is done is our legacy language allows for unquoted file
> names with spaces. Is there a better way to achieve this?
>
> Thank you,
> -Jeff
Re: Issue with white space, optional rules, and serialization [message #648457 is a reply to message #648441] Wed, 12 January 2011 23:13 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
The terminals SPACE and WS are overlapping. You are probably better of
by keeping the orginal WS rule and handle the file name parsing where
the WS rule is not hidden (i.e. hide the other hidden hidden terminals).

FILENAME hidden(ML_COMMENT, SL_COMMENT) returns xx::FileName
: ID (' '+ ID)*
;

You can use a special datatype that can report errors (such as newlines)
in the filename.

In general it is better to allow "too much" in the grammar and handle
the problems in validation as this gives an opportunity to give more
meaningful error messages than "syntax error expected... but got..." or
similar.

- henrik

On 1/12/11 11:50 PM, Jeff wrote:
> Hello,
> I have and issue with serializing a model with optional rule calls and
> redefining the WS terminal. Basically the space between keywords is not
> put in when a change is made to the model when one of the options is set.
>
> Given the grammer snippet below:
> "Hello where test"
> gets changed to
> "HelloWHERE test"
>
> Model: greetings+=Greeting*
> types+=SimpleType*
> ;
>
> Greeting:
> 'Hello' (
> ('=' '(' ('CONDITION' | 'COND') '=' condition=QualifiedName ')') |
> ('WHERE' compoundExpression=QualifiedName)
> ) ;
>
> QualifiedName :
> ID ('.' ID)*;
>
> SimpleType:
> 'type'( only?= 'ONLY')? name=ID;
>
> terminal SPACE : ' '|'\t';
> terminal WS : ('\\'(SPACE|'\r'|'\n')+) | (SPACE|'\r'|'\n')+ ;
>
>
> Note:
> The reason this is done is our legacy language allows for unquoted file
> names with spaces. Is there a better way to achieve this?
>
> Thank you,
> -Jeff
Re: Issue with white space, optional rules, and serialization [message #648620 is a reply to message #648457] Thu, 13 January 2011 17:17 Go to previous message
Jeff  is currently offline Jeff Friend
Messages: 8
Registered: February 2010
Junior Member
When I use the ' ' in the FileName rule like that then errors appear else where in my file.

Do I need to create a special datatype? I am okay with it returning a String and handling validation on my own.
I understand and would prefer to allow to much in the grammer but this proved challenging sometimes.

The actual file name looks soemthing like this:
FileName hidden(SL_COMMENT):
(ID ':\\')?
( '-'|'.' | '/' | FileNameKeyWords | FileNameBase)+
;

FileNameBase :
(FILE_NAME | NUMBER | ID | EID | STRING )
;

FileNameKeyWords :
list of keywords ....

terminal EID :
('$'('0'..'9')*ID )| '${'('0'..'9')*ID'}' | '$['('0'..'9')*ID']';
terminal NUMBER: ('0'..'9')+;
terminal FILE_NAME :
('/'|'~'|'`'|'!'|'@'|'^'|'&'|'_'|';'|'\\'|'0'..'9'|'a'..'z'|'A'..'Z')*;

I would like to clean up or remove the FILE_NAME terminal at some point too. Any suggestions are welcome

Thanks,
-Jeff
Previous Topic:Xtext workflow and GIT
Next Topic:create a class without attributes neither relations
Goto Forum:
  


Current Time: Fri Apr 19 06:19:07 GMT 2024

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

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

Back to the top