eclipse-viatra / org.eclipse.viatra

Main components of the VIATRA framework
https://eclipse.dev/viatra
Eclipse Public License 2.0
0 stars 1 forks source link

Erroneous code generation when using escape characters in vql sources. #153

Closed KocsisV closed 2 months ago

KocsisV commented 3 months ago

The code generator in Viatra 2.8.0 resolves escaped characters in string constants which results in compile errors when trying to compile the generated code.

Example vql source:

example_1 == "something in \"quotation marks\"";
example_2 == "something with backslash \\";

The resulting generated code will look like the following:

// example_1 == "something in \"quotation marks\"";
PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
new ConstantValue(body, var__virtual_1_, "something in "quotation marks"");

// example_2 == "something with backslash \\";
PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
new ConstantValue(body, var__virtual_1_, "something with backslash \");

The escaped characters are resolved and substituted, which causes compile errors.

The workaround I found is to place such strings inside an eval block. The resulting code will compile without issues this way.

example_1 == eval("something in \"quotation marks\"");
example_2 == eval("something with backslash \\");
ujhelyiz commented 3 months ago

Might be caused by the same escaping issue as #120 (but I don't consider either of them as a duplicate as they are different issues with likely the same cause.