Skip to content

Commit

Permalink
Fix match of macro argument happening within the identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ayourtch committed Aug 17, 2016
1 parent 184e4d7 commit 4b6dfdb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lcpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1268,11 +1268,11 @@ local function parseFunction(state, input)
for argname in argsstr:gmatch(IDENTIFIER) do
noargs = noargs + 1
-- avoid matching substring of another identifier (eg. attrib matches __attribute__ and replace it)
repl = repl:gsub("(#*)(%s*)("..argname..")([_%w]?)", function (s1, s2, s3, s4)
if #s4 <= 0 then
repl = repl:gsub("(#*)(%s*)([_%w]?)("..argname..")([_%w]?)", function (s1, s2, s3, s4, s5)
if #s5 <= 0 and #s3 <= 0 then
return (#s1 == 1) and ("\"$"..noargs.."\"") or (s1..s2.."$"..noargs)
else
return s1..s2..s3..s4
return s1..s2..s3..s4..s5
end
end)
end
Expand Down Expand Up @@ -1816,6 +1816,10 @@ function lcpp.test(suppressMsg)
#define _(a) -- LOOPMACRO (bi); _LOOPMACRO(ai);
_ (foo)
#undef _
#define _(t) print(t)
_(""); -- match within identifier
#undef _
msg = "check #if conditional check"
Expand Down

0 comments on commit 4b6dfdb

Please sign in to comment.