1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2025-10-27 09:59:29 +00:00

Rename built-in macros to __*__, add flag to disable built-in macros

This commit is contained in:
Étienne Fildadut 2021-06-17 18:03:34 +02:00
parent b72aff807c
commit dd22f2de3d
3 changed files with 297 additions and 290 deletions

View file

@ -28,7 +28,8 @@ candran.default = {
variablePrefix = "__CAN_",
mapLines = true,
chunkname = "nil",
rewriteErrors = true
rewriteErrors = true,
noBuiltInMacros = false
}
-- Autodetect version
@ -178,12 +179,13 @@ function candran.preprocess(input, options={})
end
-- default macros
-- TODO make it optional
env.define("__STR__(x)", function(x) return ("%q"):format(x) end)
local s = require("candran.serpent")
env.define("constexpr(expr)", function(expr)
return s.block(assert(candran.load(expr))(), {fatal = true})
end)
if not options.noBuiltInMacros then
env.define("__STR__(x)", function(x) return ("%q"):format(x) end)
local s = require("candran.serpent")
env.define("__CONSTEXPR__(expr)", function(expr)
return s.block(assert(candran.load(expr))(), {fatal = true})
end)
end
-- compile & load preprocessor
local preprocess, err = candran.compile(preprocessor, options)