Home » Archived » M2M (model-to-model transformation) » [ATL] Parsing context-free language
|
Re: [ATL] Parsing context-free language [message #35153 is a reply to message #35116] |
Sun, 29 April 2007 13:22 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hello,
Parsing context-free languages is not a model transformation issue (at
least, not if you stay within the boundaries of the Model Engineering
technical space, or technology).
However, going from context-free (or Grammarware, or EBNF) to Model
Engineering is a kind of injection (i.e., a transformation from another
technology towards Model Engineering).
The AMMA platform offers a tool to perform exactly this kind of
injection: TCS. See:
http://wiki.eclipse.org/index.php/TCS
TCS is usually used to parse a single file into a single model. You may
write a transformation (or more likely a combination of transformations,
and ant scripts) that extracts all the XML attributes that you want to
parse in separate files. Then, you may use TCS the usual way. This can
be fully automated using ant scripts and the AM3 ant tasks. See:
http://wiki.eclipse.org/index.php/AM3_Ant_Tasks
However, there is an experimental feature of ATL that you may find
extremely useful: the ability to parse a String from within the current
transformation (e.g., read from an XML attribute) into the target model
of your choice. This works by calling the following operation on your
strings:
String.inject(targetModelName : String, kind : String, params : String)
where:
- targetModelName is the name of the target model in which to create the
elements (e.g., 'OUT').
- kind is the kind of injection you want to use (e.g., 'ebnf2' for the
current version of TCS, or 'xml' for XML).
- params is a list of parameters for the injector (e.g., 'KM3' to use
the KM3 TCS parser if kind is set to 'ebnf2').
Note that you will need to put the jar (i.e., the compiled TCS parser
generated by TCS from your TCS model and KM3 metamodel) into the current
Java classpath.
As you may have noticed, it is even possible to inject an XML-encoded
String, or use any other injector from within an ATL transformation.
This feature has been tested successfully to inject an XSLT file (i.e.,
XML + XPath, which is context-free, with operators and so on) with an
XML2XSTL.atl transformation calling the String.inject(...) operation
described above. This transformation scenario has not been published yet
(stay tuned :-)).
Regards,
Frédéric Jouault
Lorenzo Dalla Vecchia wrote:
> Hi.
>
> I am currently working for a trasformation project using ATL framework.
>
> As a first step, I am injecting the input XML file of my input model in
> a ECore model by means of an ATL transformation between the XML model
> (injected from the file) and my metamodel.
>
> Now, all was proceeding well, until I encountered a problem. Some
> attributes in the source XML file contain expressions meaningful for the
> model, and that I would like to parse to generate model elements from them.
> The problem is that the language of the expressions is a context-free
> language (explointing features like nesting brackets, operator
> precedence, etc.) and therefore cannot be parsed using a simple regular
> expression.
>
> If I was using a programming language like C or Java I would have used a
> parser generator to create a parser from the language grammar, but how
> can I generate such parser in ATL code? Coding it by hand just doesn't
> seem right.
> Is there a way to somehow connect to external java classes?
>
> Thanks.
>
> --
> Lorenzo
|
|
| |
Re: [ATL] Parsing context-free language [message #36698 is a reply to message #35153] |
Wed, 09 May 2007 22:02 |
Lorenzo Dalla Vecchia Messages: 58 Registered: July 2009 |
Member |
|
|
Hi again.
> [...] there is an experimental feature of ATL that you may find extremely
> useful: the ability to parse a String from within the current
> transformation (e.g., read from an XML attribute) into the target model of
> your choice. This works by calling the following operation on your
> strings:
>
> String.inject(targetModelName : String, kind : String, params : String)
>
> where:
> - targetModelName is the name of the target model in which to create the
> elements (e.g., 'OUT').
> - kind is the kind of injection you want to use (e.g., 'ebnf2' for the
> current version of TCS, or 'xml' for XML).
> - params is a list of parameters for the injector (e.g., 'KM3' to use the
> KM3 TCS parser if kind is set to 'ebnf2').
I have prepared the TCS injector and I have its Jar ready to use.
After adding my TCS-populated model as a secondary output model in my ATL
file, and after adding the inject method call you described, I am getting
this exception during transformation.
[am3.atl] java.lang.reflect.InvocationTargetException
[am3.atl] ... 42 more
[am3.atl] Caused by: java.lang.NullPointerException
[am3.atl] at
org.atl.engine.vm.nativelib.ASMString.inject(ASMString.java: 258)
[am3.atl] ... 42 more
The exception is raised each time a call to the inject method is made.
> Note that you will need to put the jar (i.e., the compiled TCS parser
> generated by TCS from your TCS model and KM3 metamodel) into the current
> Java classpath.
It should be: I added it in the "Classpath" tab of the Ant task I am using
to run the transformation.
What could be causing the problem?
Thank you.
--
Lorenzo
|
|
|
Re: [ATL] Parsing context-free language [message #37210 is a reply to message #36698] |
Fri, 11 May 2007 13:17 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hello,
You did find a bug :-).
The String.inject(...) operation had never been tested from within
Eclipse. The current implementation depends on an object only present
when the ATL VM is launched from command line.
Best regards,
Frédéric Jouault
Lorenzo Dalla Vecchia wrote:
> Hi again.
>
>> [...] there is an experimental feature of ATL that you may find
>> extremely useful: the ability to parse a String from within the
>> current transformation (e.g., read from an XML attribute) into the
>> target model of your choice. This works by calling the following
>> operation on your strings:
>>
>> String.inject(targetModelName : String, kind : String, params : String)
>>
>> where:
>> - targetModelName is the name of the target model in which to create
>> the elements (e.g., 'OUT').
>> - kind is the kind of injection you want to use (e.g., 'ebnf2' for the
>> current version of TCS, or 'xml' for XML).
>> - params is a list of parameters for the injector (e.g., 'KM3' to use
>> the KM3 TCS parser if kind is set to 'ebnf2').
>
> I have prepared the TCS injector and I have its Jar ready to use.
> After adding my TCS-populated model as a secondary output model in my
> ATL file, and after adding the inject method call you described, I am
> getting this exception during transformation.
>
> [am3.atl] java.lang.reflect.InvocationTargetException
>
> [am3.atl] ... 42 more
>
> [am3.atl] Caused by: java.lang.NullPointerException
>
> [am3.atl] at
> org.atl.engine.vm.nativelib.ASMString.inject(ASMString.java: 258)
>
> [am3.atl] ... 42 more
>
>
> The exception is raised each time a call to the inject method is made.
>
>> Note that you will need to put the jar (i.e., the compiled TCS parser
>> generated by TCS from your TCS model and KM3 metamodel) into the
>> current Java classpath.
>
> It should be: I added it in the "Classpath" tab of the Ant task I am
> using to run the transformation.
> What could be causing the problem?
>
> Thank you.
>
> --
> Lorenzo
|
|
|
Goto Forum:
Current Time: Sat Apr 20 05:20:50 GMT 2024
Powered by FUDForum. Page generated in 0.03551 seconds
|