[TCS] More than one syntax construction per class AND optional keywords [message #380835] |
Tue, 08 January 2008 05:09  |
Eclipse User |
|
|
|
Hi everyone,
Is it possible to define more than one syntax definition per class
of the DSL metamodel. For example, something like this:
-- KM3
class NounNamePlural {
attribute name : String;
attribute plural : String;
}
-- TCS (Solution 2)
template NounNamePlural addToContext
: name "is a noun and its plural form is" plural "."
;
template NounNamePlural addToContext
: name "is a noun; its plural form is" plural "."
;
-- TCS (Solution 2)
template NounNamePlural addToContext
: name "is a noun and its plural form is" plural "."
| name "is a noun; its plural form is" plural "."
;
I know the code\syntax above doesn't work! Is there any alternative syntax
I can use? In ANTLR, I would use the | constructor. What would it be in
TCS?
The second question is: is it possible to have optional constructor? In
ANTLT it would be ( "optional terminal or nonterminal" )?. In TCS? I would
like to have:
template NounNamePlural addToContext
: name "is a noun and its plural" ("form")? is" plural "."
;
for instance.
Best regards and thank you,
Gustavo Cabral
|
|
|
|
Re: [TCS] More than one syntax construction per class AND optional keywords [message #380838 is a reply to message #380836] |
Tue, 08 January 2008 06:33  |
Eclipse User |
|
|
|
Originally posted by: quentin.glineur.obeo.fr
This is a multi-part message in MIME format.
--------------030105070206010408000408
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Hi Gustavo,
As far as I know, the square brakets are only for model to text
production. The alternatives should work without them.
For optional elements, the question mark is used.
For example:
--KM3
class NounNamePlural {
attribute name : String;
attribute plural[O..1] : String;
}
--TCS
template NounNamePlural addToContext :
(
isDefined(plural)?
name "is a noun and its plural form is " plural "." :
name "is a noun and its plural form is " name "s."
)
;
Quentin GLINEUR
Gustavo Cabral a
|
|
|
Re: [TCS] More than one syntax construction per class AND optional keywords [message #611153 is a reply to message #380835] |
Tue, 08 January 2008 05:38  |
Eclipse User |
|
|
|
Hi,
Sorry for my premature questioning. I downloaded the TCS dsl project
(CVS) and found out how to define syntax alternatives using the
[[ alt1 | alt2 .... | altN ]] constructor, like in:
template NounNamePlural addToContext
: [[ name "is a noun and its plural form is " plural "."
| name "is a noun; its plural form is" plural "."
]]
;
I still don't know how to define optional elements in my
syntax definition. :( Anyone?
regards,
Gustavo
|
|
|
Re: [TCS] More than one syntax construction per class AND optional keywords [message #611155 is a reply to message #380836] |
Tue, 08 January 2008 06:33  |
Eclipse User |
|
|
|
Originally posted by: quentin.glineur.obeo.fr
This is a multi-part message in MIME format.
--------------030105070206010408000408
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit
Hi Gustavo,
As far as I know, the square brakets are only for model to text
production. The alternatives should work without them.
For optional elements, the question mark is used.
For example:
--KM3
class NounNamePlural {
attribute name : String;
attribute plural[O..1] : String;
}
--TCS
template NounNamePlural addToContext :
(
isDefined(plural)?
name "is a noun and its plural form is " plural "." :
name "is a noun and its plural form is " name "s."
)
;
Quentin GLINEUR
Gustavo Cabral a
|
|
|
Powered by
FUDForum. Page generated in 0.04583 seconds