m-schmoock/lcpp

Multiline comment within macro definition terminates it

ayourtch opened this issue · 1 comments

Processing this chunk with lcpp:

#define foo \
   /* Comment here  \
        which spans lines */ \
   this should never appear in the output \
   but it does

causes string "this should never appear in the output but it does" to appear in the final output - whereas with cpp this does not happen.

The following diff takes care of the problem:

diff --git a/lcpp.lua b/lcpp.lua
index 4450dcd..e60f225 100755
--- a/lcpp.lua
+++ b/lcpp.lua
@@ -418,7 +418,7 @@ local function removeComments(input)
        for k, v, start, end_ in tokenizer(input, LCPP_TOKENIZE_COMMENT) do
                if k == "MLCOMMENT" then
                        local newlineCount = findn(input:sub(start, end_), "\n")
-                       local newlines = string.rep("\n", newlineCount)
+                       local newlines = string.rep("\\\n", newlineCount)^M
                        table.insert(out, newlines)
                elseif k == "SLCOMMENT" then
                        table.insert(out, "\n")