Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » A Design input request regarding external links
A Design input request regarding external links [message #662444] Wed, 30 March 2011 16:03 Go to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi,
I have a usecase where I need advice regarding design.

This is for the Puppet manifest language (.pp). The language can have
references to types and functions that are defined in Ruby. There is a
set of types and functions that are defined by the Puppet runtime. This
set can be extended in Ruby in Puppet Modules.

I have implemented the parsing of Ruby code and the result is a .pptp
(Puppet Target Platform) ecore model (containing the relevant parts from
the underlying ruby code - i.e there are instances of 'Type' and
'Function' in this model).

My DSL model (a .pp) does not use References for types and functions as
the grammar is complex and not context free - I do know during
validation if a particular ID in a semantic object should be a reference
to a type or function (or is something else). I currently validate
against a loaded .pptp model.

What I want to do is to have the overall set of available Types and
Functions be composed of (in increasing order of significance)
- a loaded ecore .pptp
- a PPTP constructed out of a set of projects in the workspace that
represents Puppet Modules (they have a manifest file in a known
location) - the files parsed by the Ruby->pptp translator are in known
locations.
- Types and Functions are in a single global namespace

The standalone (headless) usecase is simple, I know how to do that (just
load the things I need and process during validation), but I am a bit
lost when it comes to the UI part. I do want to support revalidation of
the .pp files if one of the Ruby files (in one of the puppet module
projects translated into a PPTP) changes, or if the user selects a
different TP in preferences. In other projects when using references
declared in the grammar, Xtext has handled things beautifully without me
doing anything, but now I don't know how I can reuse the same mechanisms.

I would be very grateful if someone could provide some high level
tips/steps what I would need to implement. I read the documentation
regarding IResourceDescriptions and container states etc. looked at the
mwe Reader and some code, but I am still kind of confused over what I
need to do.

In broad terms - this is needed:
1. A .rb (ruby file) change takes place in the workspace (added,
deleted, saved)
2. If this .rb file is in a particular type of project, and has a
particular path
3. Then perform translation to the effective target (PPTP model)
4. Figure out which .pp files are affected by the change
5. Revalidate them

I know how to do 1-3 (in my own way), and can come up with my own
mechanism for doing the rest - but I like to use as much as possible of
what is already available in Xtext.

Regards
- henrik
Re: A Design input request regarding external links [message #662445 is a reply to message #662444] Wed, 30 March 2011 17:01 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
I should add that the user may have DLTK Ruby installed at the same
time, and that I don't want to take over general Ruby management. (I.e.
I can't monopolize the mapping of .rb files to ecore models).

- henrik

On 3/30/11 6:03 PM, Henrik Lindberg wrote:
> Hi,
> I have a usecase where I need advice regarding design.
>
> This is for the Puppet manifest language (.pp). The language can have
> references to types and functions that are defined in Ruby. There is a
> set of types and functions that are defined by the Puppet runtime. This
> set can be extended in Ruby in Puppet Modules.
>
> I have implemented the parsing of Ruby code and the result is a .pptp
> (Puppet Target Platform) ecore model (containing the relevant parts from
> the underlying ruby code - i.e there are instances of 'Type' and
> 'Function' in this model).
>
> My DSL model (a .pp) does not use References for types and functions as
> the grammar is complex and not context free - I do know during
> validation if a particular ID in a semantic object should be a reference
> to a type or function (or is something else). I currently validate
> against a loaded .pptp model.
>
> What I want to do is to have the overall set of available Types and
> Functions be composed of (in increasing order of significance)
> - a loaded ecore .pptp
> - a PPTP constructed out of a set of projects in the workspace that
> represents Puppet Modules (they have a manifest file in a known
> location) - the files parsed by the Ruby->pptp translator are in known
> locations.
> - Types and Functions are in a single global namespace
>
> The standalone (headless) usecase is simple, I know how to do that (just
> load the things I need and process during validation), but I am a bit
> lost when it comes to the UI part. I do want to support revalidation of
> the .pp files if one of the Ruby files (in one of the puppet module
> projects translated into a PPTP) changes, or if the user selects a
> different TP in preferences. In other projects when using references
> declared in the grammar, Xtext has handled things beautifully without me
> doing anything, but now I don't know how I can reuse the same mechanisms.
>
> I would be very grateful if someone could provide some high level
> tips/steps what I would need to implement. I read the documentation
> regarding IResourceDescriptions and container states etc. looked at the
> mwe Reader and some code, but I am still kind of confused over what I
> need to do.
>
> In broad terms - this is needed:
> 1. A .rb (ruby file) change takes place in the workspace (added,
> deleted, saved)
> 2. If this .rb file is in a particular type of project, and has a
> particular path
> 3. Then perform translation to the effective target (PPTP model)
> 4. Figure out which .pp files are affected by the change
> 5. Revalidate them
>
> I know how to do 1-3 (in my own way), and can come up with my own
> mechanism for doing the rest - but I like to use as much as possible of
> what is already available in Xtext.
>
> Regards
> - henrik
>
>
>
>
Re: A Design input request regarding external links [message #662476 is a reply to message #662444] Wed, 30 March 2011 18:16 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

you'll have to provide an IResourceServiceProvier for your *.pptp model
similar to what we register for *.ecore. That implies, that you provide
an IResourceDescription.Manager which in turn produces
IResourceDescriptions for your pptp files that will be picked up and
indexed by the Xtext builder. In the IResourceDescription.Manager of
your *.pp files, you'll have to override #isAffected to trigger a
revalidation of the *.pp files when a relevant *.pptp file is modified.

If you could introduce real cross references from your *.pp to *.pptp,
this would work out of the box.
Did you consider to use something like 'Referable' as the common
supertype for Type and Function. This would allow to use actual cross
references instead of plain IDs. The advantage would be implicit
caching, since a once resolved proxy is set as a reference and many
services of Xtext (content assist, validation, #isAffected) would work
out of the box.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 30.03.11 18:03, schrieb Henrik Lindberg:
> Hi,
> I have a usecase where I need advice regarding design.
>
> This is for the Puppet manifest language (.pp). The language can have
> references to types and functions that are defined in Ruby. There is a
> set of types and functions that are defined by the Puppet runtime. This
> set can be extended in Ruby in Puppet Modules.
>
> I have implemented the parsing of Ruby code and the result is a .pptp
> (Puppet Target Platform) ecore model (containing the relevant parts from
> the underlying ruby code - i.e there are instances of 'Type' and
> 'Function' in this model).
>
> My DSL model (a .pp) does not use References for types and functions as
> the grammar is complex and not context free - I do know during
> validation if a particular ID in a semantic object should be a reference
> to a type or function (or is something else). I currently validate
> against a loaded .pptp model.
>
> What I want to do is to have the overall set of available Types and
> Functions be composed of (in increasing order of significance)
> - a loaded ecore .pptp
> - a PPTP constructed out of a set of projects in the workspace that
> represents Puppet Modules (they have a manifest file in a known
> location) - the files parsed by the Ruby->pptp translator are in known
> locations.
> - Types and Functions are in a single global namespace
>
> The standalone (headless) usecase is simple, I know how to do that (just
> load the things I need and process during validation), but I am a bit
> lost when it comes to the UI part. I do want to support revalidation of
> the .pp files if one of the Ruby files (in one of the puppet module
> projects translated into a PPTP) changes, or if the user selects a
> different TP in preferences. In other projects when using references
> declared in the grammar, Xtext has handled things beautifully without me
> doing anything, but now I don't know how I can reuse the same mechanisms.
>
> I would be very grateful if someone could provide some high level
> tips/steps what I would need to implement. I read the documentation
> regarding IResourceDescriptions and container states etc. looked at the
> mwe Reader and some code, but I am still kind of confused over what I
> need to do.
>
> In broad terms - this is needed:
> 1. A .rb (ruby file) change takes place in the workspace (added,
> deleted, saved)
> 2. If this .rb file is in a particular type of project, and has a
> particular path
> 3. Then perform translation to the effective target (PPTP model)
> 4. Figure out which .pp files are affected by the change
> 5. Revalidate them
>
> I know how to do 1-3 (in my own way), and can come up with my own
> mechanism for doing the rest - but I like to use as much as possible of
> what is already available in Xtext.
>
> Regards
> - henrik
>
>
>
>
Re: A Design input request regarding external links [message #662512 is a reply to message #662476] Wed, 30 March 2011 21:10 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Thank you Sebastian, that is most helpful. Now I understand the order in
which to proceed.

Regarding making Function and Type 'Referable'; that would not be a
problem, but specifying the references as such are, as an ID is either a
string, a variable, or a reference (to different things) depending on
what follows (far ahead).

I (think) I would have liked to be able to have parsing perform two
passes - the first to build a generic model, the second to build the
final semantic model (I don't really build a new model when validating,
but I could). An alternative for me is to push more smarts to the Lexer
(I did not have an external lexer from the start, so maybe it is
possible to do more there).

Regards
- henrik

On 3/30/11 8:16 PM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> you'll have to provide an IResourceServiceProvier for your *.pptp model
> similar to what we register for *.ecore. That implies, that you provide
> an IResourceDescription.Manager which in turn produces
> IResourceDescriptions for your pptp files that will be picked up and
> indexed by the Xtext builder. In the IResourceDescription.Manager of
> your *.pp files, you'll have to override #isAffected to trigger a
> revalidation of the *.pp files when a relevant *.pptp file is modified.
>
> If you could introduce real cross references from your *.pp to *.pptp,
> this would work out of the box.
> Did you consider to use something like 'Referable' as the common
> supertype for Type and Function. This would allow to use actual cross
> references instead of plain IDs. The advantage would be implicit
> caching, since a once resolved proxy is set as a reference and many
> services of Xtext (content assist, validation, #isAffected) would work
> out of the box.
>
> Regards,
> Sebastian
Re: A Design input request regarding external links [message #662518 is a reply to message #662476] Wed, 30 March 2011 21:55 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
A question...
On 3/30/11 8:16 PM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> you'll have to provide an IResourceServiceProvier for your *.pptp model
> similar to what we register for *.ecore.

Where is this? I googled and found references to
EcoreResourceServiceProviderImpl, and the package
"org.eclipse.xtext.ecore", but I can't find those.

- henrik
Re: A Design input request regarding external links [message #662593 is a reply to message #662518] Thu, 31 March 2011 09:05 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

please look for implementors of the AbstractGenericResourceRuntimeModule.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 30.03.11 23:55, schrieb Henrik Lindberg:
> A question...
> On 3/30/11 8:16 PM, Sebastian Zarnekow wrote:
>> Hi Henrik,
>>
>> you'll have to provide an IResourceServiceProvier for your *.pptp model
>> similar to what we register for *.ecore.
>
> Where is this? I googled and found references to
> EcoreResourceServiceProviderImpl, and the package
> "org.eclipse.xtext.ecore", but I can't find those.
>
> - henrik
>
Re: A Design input request regarding external links [message #665788 is a reply to message #662445] Fri, 15 April 2011 22:31 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
I can now ask this question:

> I should add that the user may have DLTK Ruby installed at the same
> time, and that I don't want to take over general Ruby management. (I.e.
> I can't monopolize the mapping of .rb files to ecore models).

in a more concrete way...

I want to have an emf Resource.Factory.Registry that is specific to my
language's view of resources with a particular "extension". (i.e. I am
creating a very language specific ecore model of ruby code found in
".rb" files).

Example:
My resource 'a.pp' (an xtext resource) has a reference to an EObject
with the QualifiedName X::Y which is found in the resource 'x.rb' for
which there is a Resource.Factory that creates an pptp ecore model instance.

I think I may be able to also answer the question :), but I want to make
sure I am on the right path...

Is it correct that what I need to do is to bind a specific
implementation of ResourceSet to be used by my ".pp" language, and that
when a reference is resolved, the ResourceSet's Factory.Registry is used
to get a model instance from a URI ?

- henrik
Re: A Design input request regarding external links [message #666948 is a reply to message #662593] Mon, 25 April 2011 00:51 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi,
Just a report that I now managed to get this working as I wanted.
Turned out to be very little actual coding required, but it took me
quite some time to find everything and figure out how the pieces fit
together.

Some of the difficulties are that inner classes are harder to find. When
there are no bindXXX methods in the default modules and bindings are
instead found as an @ImplementedBy annotation it makes finding things
yet a little harder. Sometimes "binding" is not done via guice and
combined with the above makes it difficult to understand what to
override (via a direct binding or by overriding something that plays a
provider role (sometimes not a guice provider). Ah, and sometimes I
would have benefited from looking at code that extends an abstract
implementation (only problem, I did not have any such implementation in
the code base I am working on...).

An additional difficulty when trying to figure out how things work is
that things are named with very similar names and when the
responsibilities of the involved parts were still unclear in my mind I
lost track numerous times of what I was looking at and why...

Uh - where in the cartisian product of "Resource", "Service",
"Provider", "Description", "I", "Impl", in singular and plural am I.

Still, overriding and extending is still a lot easier than with any
other framework I have been working with. Kudos for the design of Xtext.

Anyway - my implementation is pushed to Cloudsmith/Geppetto at github in
the 11th hour before release...

What I did (in short):
- I am now providing "target platform" contributions from ruby files by
simply loading them as EMF resources (parsing them in different ways and
transforming the result depending on the location and content of the
parsed ruby file).

- The "target SDK" everything is built against is now in a ecore file in
a "hidden" project and all projects having "my nature" adds a dynamic
reference to this project. (Note: IProject#setHidden(true) does not work
as builds does not seem to run for such projects - they can only be
hidden using "." as the initial char in the project name).

- External Linking mimics "imported names" by adding an adapter, and an
override of ResourceDescription includes these names when asked for
importedNames.

I was very happy when a change in a ruby file (magically) triggered a
rebuild of dependent code!

Again, thanks for all the help earlier.
Regards
- henrik

On 3/31/11 11:05 AM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> please look for implementors of the AbstractGenericResourceRuntimeModule.
>
> Regards,
> Sebastian
Previous Topic:Xtext builder participant OutOfMemoryError
Next Topic:Using Eclipse Templates
Goto Forum:
  


Current Time: Tue Apr 16 08:05:58 GMT 2024

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

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

Back to the top