这是indexloc提供的服务,不要输入任何密码
Skip to content

Added support for skipping children #5

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

Closed
wants to merge 1 commit into from
Closed

Added support for skipping children #5

wants to merge 1 commit into from

Conversation

regexident
Copy link
Contributor

This is particularly useful for avoiding greedy visiting when only a shallow parse is needed, e.g. to obtain method signatures, while skipping the methods' bodies.

I chose to pass a skip_children: &mut bool (with default value false), rather than adding an enum Children { Skip, Visit } and having fn visit_* return -> Children (or whatever a better name would be), as the former allows for ignoring (for non-skipping semantics), while the latter would require a Default::default() as the last line of every overridden method regardless.

With _semantics: &Semantics removed the method signatures should be fairly clean again.

(Marking this as "draft" for now as it will result in a merge conflict. I'll do a manual rebase when it's time.)

This is particularly useful for avoiding greedy visiting when only a shallow parse is needed, e.g. to obtain method signatures, while skipping the methods' bodies.
@pksunkara
Copy link
Owner

Do you think we can use some kind of DI and make SkipChildren trait or something like that? I am trying to see if we can support both visit_method_expr(self, node) and visit_method_expr(self, node, any_arg) while also allowing the user to customise the behaviour.

I might just be rambling.

@pksunkara
Copy link
Owner

pksunkara commented Oct 3, 2020

On second thought, let's go ahead with your PR. I thought about returning bool, but as you said, it wouldn't look good when we want to ignore.

But I would much rather create Options { skip_children: bool } and use options: &mut Options as the third param. This way it is more flexible for future improvement. What do you think?

@regexident
Copy link
Contributor Author

regexident commented Oct 3, 2020

Options is definitely more flexible, yes!

@pksunkara pksunkara closed this in c52bca1 Oct 9, 2020
@pksunkara
Copy link
Owner

I did this since I had some time today, hope you don't mind. I released 0.2.0 on crates.io. Hopefully, your refactor is working well. Ping me if you need anything else.

@regexident regexident deleted the visitor-skip-children branch October 15, 2020 00:08
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

Successfully merging this pull request may close these issues.

2 participants