mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 17:59:30 +00:00
Add macro support in preprocessor
This commit is contained in:
parent
66f1a5a3c2
commit
ebd36d7103
6 changed files with 5304 additions and 4763 deletions
|
|
@ -151,6 +151,54 @@ return a
|
|||
#error("preprocessor should ignore long strings")
|
||||
]])
|
||||
|
||||
test("preprocessor macro remove function", [[
|
||||
#define("log(...)", "")
|
||||
log("test")
|
||||
return true
|
||||
]], true)
|
||||
|
||||
test("preprocessor macro replace function", [[
|
||||
#define("log(x)", "a = x")
|
||||
log("test")
|
||||
return a
|
||||
]], "test")
|
||||
|
||||
test("preprocessor macro identifier replace function", [[
|
||||
#define("test(x)", "x = 42")
|
||||
test(hello)
|
||||
return hello
|
||||
]], 42)
|
||||
|
||||
test("preprocessor macro replace function with vararg", [[
|
||||
#define("log(...)", "a, b, c = ...")
|
||||
log(1, 2, 3)
|
||||
assert(a == 1)
|
||||
assert(b == 2)
|
||||
assert(c == 3)
|
||||
return true
|
||||
]], true)
|
||||
|
||||
test("preprocessor macro replace function with vararg and arg", [[
|
||||
#define("log(x, ...)", "a, b, c = x, ...")
|
||||
log(1, 2, 3)
|
||||
assert(a == 1)
|
||||
assert(b == 2)
|
||||
assert(c == 3)
|
||||
return true
|
||||
]], true)
|
||||
|
||||
test("preprocessor macro replace variable", [[
|
||||
#define("a", "42")
|
||||
return a
|
||||
]], 42)
|
||||
|
||||
test("preprocessor macro prevent recursive macro", [[
|
||||
#define("f(x)", "x")
|
||||
local x = 42
|
||||
x = f(x)
|
||||
return x
|
||||
]], 42)
|
||||
|
||||
----------------------
|
||||
-- SYNTAX ADDITIONS --
|
||||
----------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue