-
It seems ## print(
print("hello")
## ) will be transform to something like I want to transform ast before injecting Also, is it possible to implement custom annotations? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This functionality is not officially supported yet, but you can "produce" an AST from a block of statements with some meta programming tricks: ##[[
-- Utility to help getting a ast from a block of statements.
local function produce_ast(f)
-- lets hook inject_statement to capture the node
local inject_statement = ppcontext.inject_statement
local node
function ppcontext.inject_statement(_, statnode)
if node then error 'please use multiple statements inside a `do` block' end
node = statnode
end
f()
ppcontext.inject_statement = inject_statement
return node
end
]]
## local myast = produce_ast(function()
print("hello")
## end)
-- Print the AST in table form (for debugging)
## print(myast)
-- Print the AST in compact way (for debugging)
## print(myast:pretty())
## inject_statement(myast) I may make this later an official API, just have to think more on better name and use cases.
Yes, with some modding in the compiler, check this discussion for an example: Be warned that I may make a cleaner way to add annotations in the future through an official API. |
Beta Was this translation helpful? Give feedback.
This functionality is not officially supported yet, but you can "produce" an AST from a block of statements with some meta programming tricks: