Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ill transpiled code for a special script. #5

Open
mayanje opened this issue Jan 10, 2019 · 0 comments
Open

Ill transpiled code for a special script. #5

mayanje opened this issue Jan 10, 2019 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@mayanje
Copy link
Contributor

mayanje commented Jan 10, 2019

The Script below is not translated correctly.

        @{
        var items = "";
        if (@Model.definitions.nestedFunctions.Public.Count > 0) {
        items += "*\n";
        items += "*    IF CallIsCopy\n";
        items += "*      PERFORM Copy-Process-Mode\n";
        items += "*    ELSE\n";
        items += "    PERFORM FctList-Process-Mode\n";
        items += "    perform INIT-LIBRARY\n";
        items += "*    END-IF\n\n";

        items += "    GOBACK.\n\n";

        items += " FctList-Process-Mode.\n";
        items += "     IF NOT TC-" + @Model.programName8 + "-FctList-IsLoaded\n";
        foreach (var f in @Model.definitions.nestedFunctions.Concat(@Model.definitions.functions.Public, true)) {
        items += "       SET TC-"+@Model.programName8 + "-" +f.Hash+"   TO ENTRY '"+f.Hash+"'\n";
        }
        items += "       SET TC-" + @Model.programName8 + "-FctList-IsLoaded TO TRUE\n";
        items += "     END-IF\n";
        items += "        .\n\n";

        if (@Model.definitions.nestedFunctions.Public.Count > 0) {
        items += "     set PntTab-Pnt TO ADDRESS OF TC-"+@Model.programName8+"-PntTab\n";
        }
        }
        }
        @items

the resulting transpiled code is the following

@SelfResult.Append(@"
");        
        var items = "";
        if (@Model.definitions.nestedFunctions.Public.Count > 0) {
        items += "*\n";
        items += "*    IF CallIsCopy\n";
        items += "*      PERFORM Copy-Process-Mode\n";
        items += "*    ELSE\n";
        items += "    PERFORM FctList-Process-Mode\n";
        items += "    perform INIT-LIBRARY\n";
        items += "*    END-IF\n\n";

        items += "    GOBACK.\n\n";

        items += " FctList-Process-Mode.\n";
        items += "     IF NOT TC-" + @Model.programName8 + "-FctList-IsLoaded\n";
        foreach (var f in @Model.definitions.nestedFunctions.Concat(@Model.definitions.functions.Public, true)) {
        items += "       SET TC-"+@Model.programName8 + "-" +f.Hash+"   TO ENTRY '"+f.Hash+"'\n";
        }
        items += "       SET TC-" + @Model.programName8 + "-FctList-IsLoaded TO TRUE\n";
        items += "     END-IF\n";
        items += "        .\n\n";

        if (@Model.definitions.nestedFunctions.Public.Count > 0) {
        items += "     set PntTab-Pnt TO ADDRESS OF TC-"+@Model.programName8+"-PntTab\n";
        @SelfResult.Append(@"
        }
        }
");@SelfResult.Append(@"        ");@SelfResult.Append($@"{@items}");@SelfResult.Append(@"
");

The problem is that the two last } } brackets are considered by the CSharpCodeParser as Markup text thus the Tranpiler generates a String construction like:

        @SelfResult.Append(@"
        }
        }
");

This a Microsoft .Razor issue to be investigated, by taking the original CSharpCodeParser and seing what is wrong.
A work around for this issue is to transform the script like for instance like that:

        @{
        var items = "";
        if (@Model.definitions.nestedFunctions.Public.Count > 0) {
        items += "*\n";
        items += "*    IF CallIsCopy\n";
        items += "*      PERFORM Copy-Process-Mode\n";
        items += "*    ELSE\n";
        items += "    PERFORM FctList-Process-Mode\n";
        items += "    perform INIT-LIBRARY\n";
        items += "*    END-IF\n\n";

        items += "    GOBACK.\n\n";

        items += " FctList-Process-Mode.\n";
        items += "     IF NOT TC-" + @Model.programName8 + "-FctList-IsLoaded\n";
        foreach (var f in @Model.definitions.nestedFunctions.Concat(@Model.definitions.functions.Public, true))
        items += "       SET TC-"+@Model.programName8 + "-" +f.Hash+"   TO ENTRY '"+f.Hash+"'\n";
        
        items += "       SET TC-" + @Model.programName8 + "-FctList-IsLoaded TO TRUE\n";
        items += "     END-IF\n";
        items += "        .\n\n";

        if (@Model.definitions.nestedFunctions.Public.Count > 0) 
        items += "     set PntTab-Pnt TO ADDRESS OF TC-"+@Model.programName8+"-PntTab\n";        
        }
        }
        @items

AND the generated code will be:

@SelfResult.Append(@"
");        
        var items = "";
        if (@Model.definitions.nestedFunctions.Public.Count > 0) {
        items += "*\n";
        items += "*    IF CallIsCopy\n";
        items += "*      PERFORM Copy-Process-Mode\n";
        items += "*    ELSE\n";
        items += "    PERFORM FctList-Process-Mode\n";
        items += "    perform INIT-LIBRARY\n";
        items += "*    END-IF\n\n";

        items += "    GOBACK.\n\n";

        items += " FctList-Process-Mode.\n";
        items += "     IF NOT TC-" + @Model.programName8 + "-FctList-IsLoaded\n";
        foreach (var f in @Model.definitions.nestedFunctions.Concat(@Model.definitions.functions.Public, true)) {
        items += "       SET TC-"+@Model.programName8 + "-" +f.Hash+"   TO ENTRY '"+f.Hash+"'\n";
        }
        items += "       SET TC-" + @Model.programName8 + "-FctList-IsLoaded TO TRUE\n";
        items += "     END-IF\n";
        items += "        .\n\n";

        if (@Model.definitions.nestedFunctions.Public.Count > 0) {
        items += "     set PntTab-Pnt TO ADDRESS OF TC-"+@Model.programName8+"-PntTab\n";
        
        }
        }
        @SelfResult.Append($@"{@items}");@SelfResult.Append(@"
");
@mayanje mayanje added the bug Something isn't working label Jan 10, 2019
@mayanje mayanje self-assigned this Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant