Problem in code generation

Hey guys!

I'm trying to generate this piece of code (inside the fragment), the problem is that the  generated code does not contain the  hello_world as expected, instead it contains nothing….

Thank you!

1
8 comments

I see that you are using a reference macro. What is the desired target of the “hello_world” reference? USe property macros, if you only intend to replace a string value with the "hello_world_ string.

1

When you return a string in a reference macro, it will search for a node matching the name of the expected type, in this case a VariableDeclaration. Since you don't have any variable declared with the name hello_world, it will fail to generate since it can't find the referenced node by name. Generally you'd want to use mapping labels for this anyway since it is more performant. 

Like Vaclav said, you probably want to use a property macro. To do this change the first arg in the apply method call to a literal e.g. “”, then Alt+Enter and select “Add Property Macro” and return your “hello_world” string in the inspector for the macro. 

1

You should just need jetbrains.mps.baseLanguage for this

1

Experiencing a "Problem in code generation" can be frustrating for developers working on complex projects. Issues may arise from syntax errors, misconfigured environments, or logical flaws in the codebase. To resolve these, thorough debugging and systematic testing are essential. Utilizing continuous integration tools and automated testing can help catch these problems early. While managing these technical challenges, checking your Fab ATM balance Check provides a momentary break and financial reassurance. Custom promotional items like "Debugging Essentials" printed tote bags can serve as practical tools and reminders of the importance of meticulous code review and problem-solving in software development.

1

Hey huys! Thank you for your answers.

I understand what you are saying, the problem is that I dont want to generate a string literal. As you can see on the following print,  the selected line of code is an example of the code that I want to generate. As you can see, the first argument of the function is not a String literal and thats where Im having problems. 

 

This what I want to generate:

 

This is what MPS is generating (the first argument of the function is empty, and I wanted MPS to be able to let me define custom values to the first argument):

0

In that case you need the string returned in the reference macro to match that of the name of the VariableDeclaration you are referencing, or create a mapping label (better option).

In your generators' mapping configuration you'll need to add a mapping label, which maps from your input node to VariableDeclaration, then in your reference macro you need to use “genContext.get output by label and input” and supply your new label and the input node you mapped the variable declaration to.

0

Do I need to import something to be able to use “VariableDeclaration”?

0

I'm trying to generate this piece of code (inside the fragment), the problem is that the  generated code does not contain the  hello_world as expected, instead it contains nothing….

0

Please sign in to leave a comment.