Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Mode, Deep and WordRule
Mode, Deep and WordRule [message #14929] Mon, 30 June 2008 10:08 Go to next message
Eclipse UserFriend
Hi,

looking through the TCS features I do not know yet, I am puzzled about
these:
The syntax and metamodel defines deep and mode attributes for
ClassTemplates, yet I have not found an example for either in the zoo.

Also, i notice the Word rule for tokens has an attribute words, which does
not seem to do much. E.g. when I use the SPL example from the zoo, TCS
transforms

token NAME : word(
start = [alpha] | "_",
part = [alnum] | "_"
, words = ("true" : BOOLEAN, "false" : BOOLEAN)
);

to

NAME @init {}
: (((('A' .. 'Z'| 'a' .. 'z')| '_') ((('A' .. 'Z'| 'a' .. 'z'| '0' ..
'9')| '_'))*))
{

}

;

So what's the meaning of the words attribute?
Re: Mode, Deep and WordRule [message #16517 is a reply to message #14929] Wed, 09 July 2008 10:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

> looking through the TCS features I do not know yet, I am puzzled about
> these:
> The syntax and metamodel defines deep and mode attributes for
> ClassTemplates, yet I have not found an example for either in the zoo.

My advice is simplicity: if you do not need a feature, then you should
not use it.

Here are description of the two features you mention:

- "mode" can be used to dispatch to specific templates depending on the
context (i.e., you can have several templates for the same class).

- "deep abstract" makes it unnecessary to define many abstract
templates. A single one for the inheritance root is enough (provided you
do not reference the intermediate abstract classes).


> Also, i notice the Word rule for tokens has an attribute words, which
> does not seem to do much. E.g. when I use the SPL example from the zoo,
> TCS transforms
>
> token NAME : word(
> start = [alpha] | "_",
> part = [alnum] | "_"
> , words = ("true" : BOOLEAN, "false" : BOOLEAN)
> );
>
> to
> NAME @init {}
> : (((('A' .. 'Z'| 'a' .. 'z')| '_') ((('A' .. 'Z'| 'a' .. 'z'|
> '0' .. '9')| '_'))*))
> {
> }
>
> ;
>
> So what's the meaning of the words attribute?

The "false" and "true" words was necessary with ANTLR 2 when we had a
primitiveTemplate for booleans. Because "false" and "true" were not
defined as keywords in the syntax, the lexer had to have a definition of
them.

Now, the peferred way to deal with booleans is not to use a
primitiveTemplate any more, but to simply use a conditional construct:

template BooleanExp
: (value ? "true" : "false")
;

As you can see, in this version, "true" and "false" are explicitly
defined as keywords.


Regards,

Frédéric Jouault
Re: [TCS] Mode, Deep and WordRule [message #16533 is a reply to message #16517] Wed, 09 July 2008 10:59 Go to previous messageGo to next message
Eclipse UserFriend
I forgot to add (and do) that you should prefix the subject of your
TCS-related posts with [TCS].


Thanks,

Frédéric Jouault

Frédéric Jouault a écrit :
> Hi,
>
>> looking through the TCS features I do not know yet, I am puzzled about
>> these:
>> The syntax and metamodel defines deep and mode attributes for
>> ClassTemplates, yet I have not found an example for either in the zoo.
>
> My advice is simplicity: if you do not need a feature, then you should
> not use it.
>
> Here are description of the two features you mention:
>
> - "mode" can be used to dispatch to specific templates depending on the
> context (i.e., you can have several templates for the same class).
>
> - "deep abstract" makes it unnecessary to define many abstract
> templates. A single one for the inheritance root is enough (provided you
> do not reference the intermediate abstract classes).
>
>
>> Also, i notice the Word rule for tokens has an attribute words, which
>> does not seem to do much. E.g. when I use the SPL example from the
>> zoo, TCS transforms
>>
>> token NAME : word(
>> start = [alpha] | "_",
>> part = [alnum] | "_"
>> , words = ("true" : BOOLEAN, "false" : BOOLEAN)
>> );
>>
>> to
>> NAME @init {}
>> : (((('A' .. 'Z'| 'a' .. 'z')| '_') ((('A' .. 'Z'| 'a' .. 'z'|
>> '0' .. '9')| '_'))*))
>> {
>> }
>>
>> ;
>>
>> So what's the meaning of the words attribute?
>
> The "false" and "true" words was necessary with ANTLR 2 when we had a
> primitiveTemplate for booleans. Because "false" and "true" were not
> defined as keywords in the syntax, the lexer had to have a definition of
> them.
>
> Now, the peferred way to deal with booleans is not to use a
> primitiveTemplate any more, but to simply use a conditional construct:
>
> template BooleanExp
> : (value ? "true" : "false")
> ;
>
> As you can see, in this version, "true" and "false" are explicitly
> defined as keywords.
>
>
> Regards,
>
> Frédéric Jouault
Re: [TCS] Mode, Deep and WordRule [message #16695 is a reply to message #16533] Fri, 18 July 2008 08:03 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

thanks for the explanation.

>> Here are description of the two features you mention:
>>
>> - "mode" can be used to dispatch to specific templates depending on the
>> context (i.e., you can have several templates for the same class).

I see this also works for abstract templates, as long as all subtemplates
also specify that mode. I guess it would also work for operatored
templates?

>>> Also, i notice the Word rule for tokens has an attribute words, which
>>> does not seem to do much. E.g. when I use the SPL example from the
>>> zoo, TCS transforms
>>> So what's the meaning of the words attribute?
>>
>> The "false" and "true" words was necessary with ANTLR 2 when we had a
>> primitiveTemplate for booleans.
>>
>> As you can see, in this version, "true" and "false" are explicitly
>> defined as keywords.

So the words attribute is ignored by TCS when using ANTLR 3?
Re: [TCS] Mode [message #18130 is a reply to message #16695] Mon, 21 July 2008 05:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

wehn I try using an operatored moded template, i get a NullPointerException

Such as
template Expression #test operatored
: "Test"
;

java.lang.NullPointerException
[am3.saveModel] at
org.eclipse.m2m.atl.engine.vm.nativelib.AMN.getInt(AMN.java: 53)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.eval(TCSExtractor .java:558)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.eval(TCSExtractor .java:525)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:503)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serialize(TCSExtr actor.java:275)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:611)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:594)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:432)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serialize(TCSExtr actor.java:275)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:611)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:432)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:506)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serialize(TCSExtr actor.java:275)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:611)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:594)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:432)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:489)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.serialize(TCSExtr actor.java:275)
[am3.saveModel] at
org.eclipse.gmt.tcs.extractor.TCSExtractor.extract(TCSExtrac tor.java:210)
[am3.saveModel] at
org.eclipse.gmt.am3.tools.ant.toolkit.AM3AntToolKit$2.run(AM 3AntToolKit.java:459)
Re: [TCS] Mode [message #18246 is a reply to message #18130] Wed, 23 July 2008 11:07 Go to previous message
Eclipse UserFriend
Hi,

Modes currently do not work with operatored templates.


Regards,

Frédéric Jouault

Thibault a écrit :
> Hi,
>
> wehn I try using an operatored moded template, i get a NullPointerException
>
> Such as
> template Expression #test operatored
> : "Test"
> ;
>
> java.lang.NullPointerException
> [am3.saveModel] at
> org.eclipse.m2m.atl.engine.vm.nativelib.AMN.getInt(AMN.java: 53)
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.eval(TCSExtractor .java:558)
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.eval(TCSExtractor .java:525)
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:503)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serialize(TCSExtr actor.java:275)
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:611)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:594)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:432)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serialize(TCSExtr actor.java:275)
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:611)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:432)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:506)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serialize(TCSExtr actor.java:275)
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:611)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeProperty (TCSExtractor.java:594)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:432)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeqElem( TCSExtractor.java:489)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serializeSeq(TCSE xtractor.java:392)
>
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.serialize(TCSExtr actor.java:275)
> [am3.saveModel] at
> org.eclipse.gmt.tcs.extractor.TCSExtractor.extract(TCSExtrac tor.java:210)
> [am3.saveModel] at
> org.eclipse.gmt.am3.tools.ant.toolkit.AM3AntToolKit$2.run(AM 3AntToolKit.java:459)
>
>
>
Previous Topic:Model to grammar
Next Topic:[TCS] TCS and UML profiles
Goto Forum:
  


Current Time: Mon Jul 14 16:05:13 EDT 2025

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

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

Back to the top