Generating code in two places, weaving rules

I am trying to do another thing that is probably straightforward but is giving me a lot of problems:

I need a DSL statement to generate code in two places in the output: at the top of the main method for initialization, and within an infinite loop for use. I can use a COPY_SRC macro for one of them, but generating the second one is harder. I am guessing that I must use a weaving rule, but whenever I try to attach a mapping label to a block statement or the loop itself and try to use it, I get messages that say things along the lines of "no child role statement known for... source node's... BlockStatement concept".

I must be misunderstanding what I am supposed to be labeling, and how to tell the weaving rule where to place the node. Can someone help with an explanation?

I saw another question on the forum along these lines, but the answer suggested looking at the generator demos, which I have completed. They did not clarify the matter for me. Numerous experiments also have yet to succeed.

Could someone shed more light on this?

Thank you.

1 comment

I never could figure out how to properly reference a location for a weaving rule context, so if someone could give an example (placing code inside a block statement, for instance), that would be great.

In the meantime, for anyone trying to do the same thing, a simple solution that does not involve weaving rules is the following:

Create a statement to serve as a hook for your new code as usual. Select it and add a loop macro that loops over the nodes you need to generate code from (remember to select the whole statement, including the semicolon, or you'll get cardinality errors). Now select it and add an "if" macro in which you can define the conditions for generating the code (in the inspector. You may not need this if this code always has to be generated). Now select it a third time and add an "include" macro that includes the template you need.

I overlooked this simple solution earlier because "include" macros do not allow you to define conditions, and I needed them.

If someone wants to give an example of using weaving rules instead, please do.


Please sign in to leave a comment.