Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [TCS] How to define empty string ?
[TCS] How to define empty string ? [message #10145] Tue, 15 April 2008 12:12 Go to next message
Eclipse UserFriend
Originally posted by: romain.perruchon.thalesgroup.com

Hi,

I have lines defines like this :

template Ligne
: aa";"bb";"cc";"dd";"ee
;

My language can contain lines like this :
;;xxx;yyy;zzz

with empty values between ";"

How can I explain in my tcs these possibly empty values ?
I try several manner in the lexer to define STRING but fail.

I have this actually :

STRING
:
(
~(';' |'\\\\'|'\\''|'\\n')
)*
;

This works with lines without empty values.

Thanks
Re: [TCS] How to define empty string ? [message #10166 is a reply to message #10145] Wed, 16 April 2008 03:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Generally, if you have a specific construct in the concrete syntax, it
corresponds to a specific construct in the metamodel.

For instance, given program:
aa;bb;;cc;dd;;;ee;

you could create the following metamodel:

class List {
reference elements[*] ordered container : Element;
}

abstract class Element {}

class NamedElement extends Element {
attribute name : String;
}

class EmptyElement extends Element {}


and the following TCS model:

template List main
: elements
;

template Element abstract;

template NamedElement
: name ";"
;

template EmptyElement
: ";"
;


This pattern can for instance be used to represent statements and empty
statements in languages that support this.


When transforming a program with empty elements, you can decide whether
you want to ignore empty elements or not. However, if you made this
decision at the TCS level you would already do some structural change.



Regards,

Frédéric Jouault

romain Perruchon a écrit :
> Hi,
>
> I have lines defines like this :
>
> template Ligne
> : aa";"bb";"cc";"dd";"ee
> ;
>
> My language can contain lines like this :
> ;;xxx;yyy;zzz
>
> with empty values between ";"
>
> How can I explain in my tcs these possibly empty values ?
> I try several manner in the lexer to define STRING but fail.
>
> I have this actually :
>
> STRING
> :
> (
> ~(';' |'\\\\'|'\\''|'\\n')
> )*
> ;
>
> This works with lines without empty values.
>
> Thanks
>
Re: [TCS] How to define empty string ? [message #12250 is a reply to message #10166] Wed, 16 April 2008 05:29 Go to previous message
Eclipse UserFriend
Originally posted by: romain.perruchon.thalesgroup.com

Thanks for reply frederic.

It was simple but I didn't think like this. I understand now my mistake.
Previous Topic:[TCS] isDefined vs. Alternative
Next Topic:Re: Xtext (4.3 beta) for EMF resources
Goto Forum:
  


Current Time: Thu May 08 03:49:07 EDT 2025

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

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

Back to the top