Side Transforms on Children vs. Properties

Hello all,

I was able to implement a side transform for my scenario with a little bit of cajouling, but I am hitting an issue where it will work with a property but not a child.

My side transform looks like:

side transform actions usingNamespaceAlias                                                                                                                                             

right transformed node: UsingDirective tag: default_  //namespace alias assignment

  condition :                                                                                                                                                                         

    (operationContext, scope, model, sourceNode)->boolean {

  sourceNode.namespaceAlias == null && sourceNode.namespace != null;

}                                                   

                                                                                                                                                                                       

  common initializer :                                                                                                                                                                 

    <no common variables>                                                                                                                                                             

    ....................................                                                                                                                                               

    <no common initializer>                                                                                                                                                           

                                                                                                                                                                                       

  actions :                                                                                                                                                                           

                                                                                                                                                                                       

    add custom items  (output concept: UsingDirective)                                                                                                                                 

      simple item                                                                                                                                                                     

        matching text                                                                                                                                                                 

          =                                                                                                                                                                           

        description text                                                                                                                                                               

          namespace alias assignment                                                                                                                                                   

        icon                                                                                                                                                                           

          <default>                                                                                                                                                                   

        type                                                                                                                                                                           

          <default>                                                                                                                                                                   

        do transform                                                                                                                                                                   

          (operationContext, scope, model, sourceNode, pattern)->node< > {

  sourceNode.namespaceAlias = sourceNode.namespace;

  sourceNode.namespace = null;

  return sourceNode;

}

The working version of my concept is currently:

concept UsingDirective extends BaseConcept   

                       implements <none>     

                                             

...               

                                             

  properties:                                 

  namespaceAlias : Identifier                 

  namespace : string 

...       

with an editor of:

[> using ?[> { namespaceAlias } = <] { namespace } <]

However, if I change my concept to:

concept UsingDirective extends BaseConcept   

                       implements <none>     

                                             

...         

                                             

  properties:                                 

  namespaceAlias : Identifier               

                                             

  children:                                   

  Namespace namespace 1 specializes: <none>                         


...

with an editor of:

[> using ?[> { namespaceAlias } = <] ( % namespace % -> { name } ) <]

I can no longer get my side transform to work, even with modifying it to look at the child instead of the property.

My theory is because the active node is no longer a UsingDirective, but a Namespace nested within that UsingDirective, the side transform is no longer active.

Are side transforms supported on children like I am attempting to do, or do I need to stick to using a property for namespace?

Thanks for any guidance.

Robert

5 comments
Comment actions Permalink

Hello Robert,

Yes, you are right. Active node is Namespace. You can write side transform for Namespace instead of UsingDirective.

Side transform will be somethig like this:

side transform actions usingNamespaceAlias                                                                                                                                           

right transformed node: Namespace tag: default_  //namespace alias assignment

condition:                                                                                                                                                                       

    (operationContext, scope, model, sourceNode)->boolean {

    node<UsingDirective> parent = sourceNode.parent : UsingDirective;

  parent.namespaceAlias == null && parent.namespace != null;

}                                                 

                                                                                                                                                                                     

common initializer:                                                                                                                                                               

    <no common variables>                                                                                                                                                           

    ....................................                                                                                                                                             

    <no common initializer>                                                                                                                                                         

                                                                                                                                                                                     

actions :                                                                                                                                                                         

                                                                                                                                                                                     

    add custom items  (output concept: UsingDirective)                                                                                                                               

      simple item                                                                                                                                                                   

        matching text                                                                                                                                                               

          =                                                                                                                                                                         

        description text                                                                                                                                                             

          namespace alias assignment                                                                                                                                                 

        icon                                                                                                                                                                         

          <default>                                                                                                                                                                 

        type                                                                                                                                                                         

          <default>                                                                                                                                                                 

        do transform                                                                                                                                                                 

          (operationContext, scope, model, sourceNode, pattern)->node< > {

  node<UsingDirective> parent = sourceNode.parent : UsingDirective;

  parent.namespaceAlias = sourceNode.namespace;

  parent.namespace = null;

  return parent;

}

Regards,

Evgeny

0
Comment actions Permalink

Hello, Evgeny,

Oh!  So, a side transform is not limited to modifying the node which it captured.  I incorrectly assumed that you could only modify the current node and its children/properties...

That is very powerful!

I am still struggling with making the transform fire with this setup, but I think I just have something set up wrong...

Thank you for your help! :-)  Looking forward to MPS 1.0!

Robert

0
Comment actions Permalink

OK, I finally got it, but it was a little weird.

If the type of the property was string, the side transform didn't want to fire, for some reason.

Using a constrained data type that takes every character except the one that should fire the side transform seems to do the trick. (in this case, [^=]*)

It's working wonderfully now, though.  Thanks again! :-)

0
Comment actions Permalink

Robert,

Right transform is activated on a first non valid character.

Regards,

Konstantin

0
Comment actions Permalink

Hi, Konstantin,

Ah, okay... that makes perfect sense, then. :-)  Thank you!

I am really enjoying side transforms!

Thanks again. :-)

Robert

0

Please sign in to leave a comment.