Skip to content

Commit be773d9

Browse files
committed
Fixed sometimes bad output when a preprocessor line ended with a comment.
1 parent 84cb0d3 commit be773d9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

misc/quickTest.lua2p

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ print("Final program - uhh: "..uhh)
6969
-- Misc.
7070
print(!("dataFromCommandLine: "..tostring(dataFromCommandLine)))
7171
print(!(("This file and line: %s:%d"):format(@file, @line)))
72+
73+
for i = 1, 3 do
74+
do
75+
!outputLua("break")
76+
end
77+
!outputLua("break") -- Just a comment.
78+
end
79+
7280
print("The end.")
7381

7482
!(

preprocess.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,12 +1758,18 @@ local function _processFileOrString(params, isFile)
17581758

17591759
-- Fix whitespace after the line.
17601760
local tokNext = tokens[tokenIndex]
1761-
if not isDual and tokType == "whitespace" and not (tokNext and isToken(tokNext, "pp_entry")) then
1761+
if isDual or (tokNext and isToken(tokNext, "pp_entry")) then
1762+
-- void
1763+
1764+
elseif tokType == "whitespace" then
17621765
local tokExtra = copyTable(tok)
17631766
tokExtra.value = tok.value:gsub("^[^\n]+", "")
17641767
tokExtra.representation = tokExtra.value
17651768
tokExtra.position = tokExtra.position+#tok.value-#tokExtra.value
1769+
table.insert(tokensToProcess, tokExtra)
17661770

1771+
elseif tokType == "comment" and not tok.long then
1772+
local tokExtra = {type="whitespace", representation="\n", value="\n", line=tok.line, position=tok.position}
17671773
table.insert(tokensToProcess, tokExtra)
17681774
end
17691775

0 commit comments

Comments
 (0)