Skip to content

Commit 8ea2f48

Browse files
committed
Making sure @insert and the following token came from the same file.
1 parent 4b20c37 commit 8ea2f48

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

preprocess.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,7 @@ local function doLateExpansionsResources(tokensToExpand, fileBuffers, params, st
18791879
local tokNext, iNext = getNextUsableToken(tokenStack, #tokenStack-1, nil, -1)
18801880

18811881
-- @insert "name"
1882-
if ppKeywordTok.value == "insert" and isTokenAndNotNil(tokNext, "string") then
1882+
if ppKeywordTok.value == "insert" and isTokenAndNotNil(tokNext, "string") and tokNext.file == ppKeywordTok.file then
18831883
local nameTok = tokNext
18841884
popTokens(tokenStack, iNext) -- the string
18851885

@@ -1936,7 +1936,7 @@ local function doLateExpansionsResources(tokensToExpand, fileBuffers, params, st
19361936
-- @insert identifier ( argument1, ... )
19371937
-- @insert identifier " ... "
19381938
-- @insert identifier { ... }
1939-
elseif ppKeywordTok.value == "insert" and isTokenAndNotNil(tokNext, "identifier") then
1939+
elseif ppKeywordTok.value == "insert" and isTokenAndNotNil(tokNext, "identifier") and tokNext.file == ppKeywordTok.file then
19401940
local identTok = tokNext
19411941
tokNext, iNext = getNextUsableToken(tokenStack, iNext-1, nil, -1)
19421942

@@ -2034,6 +2034,7 @@ local function processPreprocessorBlockInMacroArgument(tokens, fileBuffers, toke
20342034
end
20352035

20362036
local function expandMacro(tokens, fileBuffers, tokenStack, macroStartTok, isNested)
2037+
-- @Robustness: Make sure key tokens came from the same source file.
20372038
local tokNext, iNext = getNextUsableToken(tokenStack, #tokenStack-1, nil, -1)
20382039

20392040
if not isTokenAndNotNil(tokNext, "identifier") then

tests/quickTest.lua2p

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ print(s:match(funcCall)) -- "hello5( foo )"
7979
@insert "tests/quickTest.luapart"
8080
print("Metaprogram - someString: "..someString)
8181
)
82-
local uhh1 = !(@insert"tests/quickTest.txt")
83-
local uhh2 = !(@@"tests/quickTest.txt") -- @@ means the same as @insert.
82+
local uhh1 = !(@insert"tests/quickTest_expression.txt")
83+
local uhh2 = !(@@"tests/quickTest_expression.txt") -- @@ means the same as @insert.
8484
print("Final program - uhh: "..uhh1..", "..uhh2)
8585

8686

@@ -129,7 +129,7 @@ local f = @@PASS_THROUGH(function(a, b)
129129
return "", nil
130130
end)
131131

132-
local x = @@PASS_THROUGH( @@"tests/quickTest.txt" )
132+
local x = @@PASS_THROUGH( @@"tests/quickTest_expression.txt" )
133133

134134
local x1 = @@PASS_THROUGH( 1 + !!( "2" ) + 3 )
135135
local x2 = @@PASS_THROUGH{ 1 + !!( "2" ) + 3 }

tests/quickTest_name.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type

0 commit comments

Comments
 (0)