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 before multi-using statements are erased #122

Closed dadhi closed 3 years ago

dadhi commented 3 years ago

Hi @qwertie

I have an issue with comments erasure in output in LeMP v2.8.1 in here: https://github.com/dadhi/LempTest/blob/e59710f676c815a272e4ebe80cd9ca00ccd0c601/CompileTimeDI/CompileTimeDI.ecs#L4.

The result: https://github.com/dadhi/LempTest/blob/master/CompileTimeDI/CompileTimeDI.Generated.cs

I am running the LeMP with the following options: https://github.com/dadhi/LempTest/blob/e59710f676c815a272e4ebe80cd9ca00ccd0c601/CompileTimeDI/CompileTimeDI.csproj#L62

qwertie commented 3 years ago

Confirmed, this is a bug in the macro that processes using statements. Often, comments attached to a statement will disappear if the applicable macro doesn't take steps to preserve them. (This has been a recurring problem because it is easier to write a macro that ignores comments than one that preserves them in its output.)

qwertie commented 3 years ago

A workaround for this is to attach the comment to a #rawText("") statement instead. #rawText(""); is a dummy node that causes an empty string to be written to the output file.

// This comment will be preserved
#rawText("");
dadhi commented 3 years ago

Thankd for suggesting the workaround. I imagine that I can abuse #rawText("") for other things too.

qwertie commented 3 years ago

This should be fixed in v28.3 (2.8.3)