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

Add iterative search/replace example to examples and README.md #383

Merged
merged 3 commits into from
Apr 28, 2024

Conversation

kaesluder
Copy link
Contributor

revise #369

Add iterative string search/replace example to examples and README.md. The new example uses the AstNode.descendants() iterator to examine all nodes in a tree. This should be easy to understand for newcomers. Code example is wrapped as a function which should be easy to copy/paste into a sandbox, file, or other setup.

Note: example would need additional error checking for production code.

Basic "happy path" unit test in examples/iterator-replace.

kaesluder and others added 3 commits April 26, 2024 22:58
Updated the AST example on README.md to use AstNode.descendants() as
convenience iterator.

1. Using the iterator should be sufficient for most cases and is
hopefully more familiar to people with experience at DOM/AST
manipulation in other languages.
2. Full example in examples/iterator_replace.rs. It should be possible
to drop the whole block from README into a file and run the demo.
3. Ref and lifetime allocation for this example is encapsulated in the
Arena and AstNode methods.
1. Check comments for accuracy
2. Add basic unit test. Test checks output for string replacement and
use of key html tags. Not sensitive to whitespace handling.
3. Remove unnecessary to_string() calls from main() and test function.
@kivikakk
Copy link
Owner

This is perfect — thank you so much, again! 😊🤍

@kivikakk kivikakk merged commit cd272a7 into kivikakk:main Apr 28, 2024
12 of 13 checks passed
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