qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
172 stars 25 forks source link

Comments not emitted based on surrounding whitespace #59

Closed j4m3z0r closed 3 years ago

j4m3z0r commented 5 years ago

While researching the test-cases in #58, I discovered that newlines surrounding comments can affect whether or not the comments are emitted in the output. For example:

#ecs;

namespace Test
{
    internal class Class
    {
        // #region test region

        [DllImport(Constants.Lib, EntryPoint = "testfunction")]
        public static extern int TestFunction(int i);
        //#endregion
    }
}

Will omit the first comment, whereas the comment is preserved in either of the following two versions:

#ecs;

namespace Test
{
    internal class Class
    {
        // #region test region
        [DllImport(Constants.Lib, EntryPoint = "testfunction")]
        public static extern int TestFunction(int i);
        //#endregion
    }
}
#ecs;

namespace Test
{
    internal class Class
    {

        // #region test region

        [DllImport(Constants.Lib, EntryPoint = "testfunction")]
        public static extern int TestFunction(int i);
        //#endregion
    }
}
qwertie commented 5 years ago

Wow, this seems somehow connected to the #ecs macro; removing it or replacing it with something else preserves the comment. Changing the class into a method or property also fixes it. The blank line often disappears from the output, which is likely to be a separate bug.

qwertie commented 3 years ago

This will be fixed in the 2.9.0 release. The bug was in #useSymbols which is part of #ecs. This macro would always recreate the braced block of a class, struct, or interface. So a comment, newline or #region would disappear if it was attached to the opening brace (body.Target) of a class, struct or interface.