[TCS] How to do a substring ? [message #377479] |
Thu, 10 May 2007 07:00  |
Eclipse User |
|
|
|
Hi all,
Is it possible to do a sort of substring operation in TCS ?
In my example i've got a string like this "10101604" in my text file
and i want to cut it in 4 ones to put them in separate attributes.
For now i use an intermediate metamodel and a trasformation to get the
model i want. Can i do it without this intermediary model ?
any idea ?
|
|
|
Re: [TCS] How to do a substring ? [message #377483 is a reply to message #377479] |
Thu, 10 May 2007 08:16  |
Eclipse User |
|
|
|
Hello,
> Is it possible to do a sort of substring operation in TCS ?
> In my example i've got a string like this "10101604" in my text file and
> i want to cut it in 4 ones to put them in separate attributes.
TCS handles the syntax of DSLs (i.e., a grammar is generated from a TCS
model). The lexical aspects have to be handled in the lexer, which can
be defined in the TCS file, but using ANTLR syntax.
Once "10101604" has been recognized by the lexer as a single token, TCS
will not be able to break it apart.
> For now i use an intermediate metamodel and a trasformation to get the
> model i want. Can i do it without this intermediary model ?
> any idea ?
- You may change the lexer to tokenize your input according to what you
want. The documentation of ANTLR may be helpful:
http://www.antlr.org/doc/lexer.html#Lexical_Analysis_with_AN TLR
- You may keep only the intermediate metamodel and define a helper in
your transformations to break the string. This helper may be put in a
library if different transformations use it. This solution gets rid of
the additional transformation step but does not give you a "clean" model.
Regards,
Frédéric Jouault
|
|
|
Re: [TCS] How to do a substring ? [message #596119 is a reply to message #377479] |
Thu, 10 May 2007 08:16  |
Eclipse User |
|
|
|
Hello,
> Is it possible to do a sort of substring operation in TCS ?
> In my example i've got a string like this "10101604" in my text file and
> i want to cut it in 4 ones to put them in separate attributes.
TCS handles the syntax of DSLs (i.e., a grammar is generated from a TCS
model). The lexical aspects have to be handled in the lexer, which can
be defined in the TCS file, but using ANTLR syntax.
Once "10101604" has been recognized by the lexer as a single token, TCS
will not be able to break it apart.
> For now i use an intermediate metamodel and a trasformation to get the
> model i want. Can i do it without this intermediary model ?
> any idea ?
- You may change the lexer to tokenize your input according to what you
want. The documentation of ANTLR may be helpful:
http://www.antlr.org/doc/lexer.html#Lexical_Analysis_with_AN TLR
- You may keep only the intermediate metamodel and define a helper in
your transformations to break the string. This helper may be put in a
library if different transformations use it. This solution gets rid of
the additional transformation step but does not give you a "clean" model.
Regards,
Frédéric Jouault
|
|
|
Powered by
FUDForum. Page generated in 0.02946 seconds