-
Notifications
You must be signed in to change notification settings - Fork 286
NodeIterator #861
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
NodeIterator #861
Conversation
fe1e3ef to
cf5815e
Compare
|
I'll look at the PR more completely in a bit, but I do think the issue is likely related to the implementation of the NodeIterator. When I debug this, I see that the callback is called with a Node (as well as other elements), despite the code using the Without looking at the implementation, I assume it's either emitting a node when it shouldn't (because of the filter), or it's emitting an element as a node without going through the |
| const node_type = try parser.nodeType(node); | ||
|
|
||
| // Verify that we can show this node type. | ||
| if (!switch (node_type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Zig-ish alternative to this is @bitCast the u32 into a packed struct:
pub const WhatToShow = packed struct {
element: bool,
attribute: bool,
text: bool,
cdata: bool,
entity_reference: bool,
entity: bool,
processing_instruction: bool,
comment: bool,
document: bool,
document_type: bool,
document_fragment: bool,
notation: bool,
_: u20,
};
pub fn verify(what_to_show: u32, filter: ?Env.Function, node: *parser.Node) !VerifyResult {
const node_type = try parser.nodeType(node);
// or WhatToShow.fromBitmask(what_to_show) if you want to encapsulate it
const wts: WhatToShow = @bitCast(what_to_show);
if (!switch (node_type) {
.attribute => wts.atribute,
, ....
})There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Good to know.
In this case I'm inclined to leave it as it was. Just fewer loc.
If you do feel strongly about I would also change the u32 stored in the NodeIterator and TreeWalker, and cast it back when that property is accessed. Otherwise I'll leave it as is.
|
LGTM |
93ea4ed to
2842fca
Compare

https://developer.mozilla.org/en-US/docs/Web/API/Document/createNodeIterator
Does not reuse the TreeWalker implementation as there are several subtle differences
TreeWalker is likely not handling its edges cases correctly, those are not addressed in this PR except fixing,
get_filter(),_previous_node()going beyond the root and functions returning*parser.Nodeinstead ofNode.Union