Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow compute_reactive_node and compute_symbols_state to walk macros with a kwarg. #21

Closed
0x0f0f0f opened this issue Aug 1, 2024 · 2 comments

Comments

@0x0f0f0f
Copy link

0x0f0f0f commented Aug 1, 2024

The application I'm building requires walking all expressions, including arguments of macro calls. How hard would it be to have a kwarg that does that?

@0x0f0f0f
Copy link
Author

0x0f0f0f commented Aug 1, 2024

The application I'm building requires walking all expressions, including arguments of macro calls.

It checks for presence of symbols and it doesn't really care about if the macroexpanded source code does not reference some symbols anymore

@fonsp
Copy link
Member

fonsp commented Aug 8, 2024

Hey @0x0f0f0f ! Nice to hear that you're using ExpressionExplorer!

Our idea here was that we don't need so much API in ExpressionExplorer, because you can transform expressions before passing them to ExpressionExplorer.

In the README, there is an example of expanding macros before using ExpressionExplorer. I'm assuming that this doesn't work for you because you are doing static analysis (so you can't run the macros)?

In that case, you could just change the Expression into something that ExpressionExplorer will understand. I think you could search for all macrocalls, find all the argument expressions, and add them to the tree outside of a macro call. For example:

this_is_an_example(expression)

@somemacro with [multiple, :arguments]

You could turn this into:

this_is_an_example(expression)

begin
	@somemacro with [multiple, :arguments]
	with 
	[multiple, :arguments]
end

Now, the arguments are visible to ExpressionExplorer because they do not appear inside a macrocall.

Code example

The code might look something like this:

function with_macrocall_args_exposed(e::Expr)
	if e.head === :macrocall
		Expr(
			:block,
			# the original call
			e,
			# the arguments, added as regular expressions
			(with_macrocall_args_exposed(a) for a in e.args)...,
		)
	else
		e
	end
end

with_macrocall_args_exposed(x) = x

ExpressionExplorer.compute_reactive_node(with_macrocall_args_exposed(my_expr))

@fonsp fonsp closed this as completed Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants