Skip to content

Commit f7d5749

Browse files
committed
@@foo!() and @@foo!!()
1 parent 2d62c0a commit f7d5749

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

preprocess.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,13 +1991,16 @@ local function doLateExpansionsResources(tokensToExpand, fileBuffers, params, st
19911991
-- @insert identifier ( argument1, ... )
19921992
-- @insert identifier " ... "
19931993
-- @insert identifier { ... }
1994+
-- @insert identifier !( ... )
1995+
-- @insert identifier !!( ... )
19941996
elseif ppKeywordTok.value == "insert" and isTokenAndNotNil(tokNext, "identifier") and tokNext.file == ppKeywordTok.file then
19951997
local identTok = tokNext
19961998
tokNext, iNext = getNextUsableToken(tokenStack, iNext-1, nil, -1)
19971999

19982000
if not (tokNext and (
19992001
tokNext.type == "string"
20002002
or (tokNext.type == "punctuation" and isAny(tokNext.value, "(","{",".",":","["))
2003+
or tokNext.type == "pp_entry"
20012004
)) then
20022005
errorAtToken(fileBuffers, identTok, identTok.position+#identTok.representation, "Macro", "Syntax error: Expected '(' after macro name '%s'.", identTok.value)
20032006
end
@@ -2406,6 +2409,24 @@ local function expandMacro(tokens, fileBuffers, tokenStack, macroStartTok, isNes
24062409
-- Add ')' for end of call.
24072410
tableInsert(tokens, tableRemove(tokenStack)) -- ')'
24082411

2412+
-- @insert identifier !( ... )
2413+
-- @insert identifier !!( ... )
2414+
elseif isTokenAndNotNil(tokNext, "pp_entry") then
2415+
popTokens(tokenStack, iNext+1) -- until '!' or '!!'
2416+
2417+
-- Add '(' for start of call.
2418+
if not isTokenAndNotNil(tokenStack[#tokenStack-1], "punctuation", "(") then
2419+
local tok = (tokenStack[#tokenStack-1] or tokenStack[#tokenStack])
2420+
errorAtToken(fileBuffers, tok, nil, "Macro", "Expected '(' after '!'.")
2421+
end
2422+
tableInsert(tokens, newTokenAt({type="punctuation", value="(", representation="("}, tokNext))
2423+
2424+
processPreprocessorBlockInMacroArgument(tokens, fileBuffers, tokenStack)
2425+
2426+
-- Add ')' for end of call.
2427+
assert(isTokenAndNotNil(tokens[#tokens], "punctuation", ")"))
2428+
tableInsert(tokens, newTokenAt({type="punctuation", value=")", representation=")"}, tokens[#tokens]))
2429+
24092430
else
24102431
errorAfterToken(fileBuffers, lastCalleeTok, "Macro", "Syntax error: Expected '(' after macro name.")
24112432
end
@@ -2424,6 +2445,8 @@ local function doLateExpansionsMacros(tokensToExpand, fileBuffers, params, stats
24242445
-- @insert identifier ( argument1, ... )
24252446
-- @insert identifier " ... "
24262447
-- @insert identifier { ... }
2448+
-- @insert identifier !( ... )
2449+
-- @insert identifier !!( ... )
24272450
--
24282451
if not stats.hasPreprocessorCode then
24292452
return tokensToExpand
@@ -2446,6 +2469,8 @@ local function doLateExpansionsMacros(tokensToExpand, fileBuffers, params, stats
24462469
-- @insert identifier ( argument1, ... )
24472470
-- @insert identifier " ... "
24482471
-- @insert identifier { ... }
2472+
-- @insert identifier !( ... )
2473+
-- @insert identifier !!( ... )
24492474
if ppKeywordTok.value == "insert" then
24502475
expandMacro(tokens, fileBuffers, tokenStack, ppKeywordTok, false)
24512476

tests/quickTest.lua2p

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ local d = @@PASS_THROUGH(@@PASS_THROUGH{@@PASS_THROUGH( !!("1")!!("+")!!("2") )}
138138
!local keys = {"object"}
139139
local n = @@t.field[keys[1]]:method(58)
140140

141+
!local function ADD1(lua) return lua.."+1" end
142+
local n1 = @@ADD1!(43-2)
143+
local n2 = @@ADD1!!("43-2")
144+
141145

142146

143147
-- Misc.

0 commit comments

Comments
 (0)