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

modifies components + adds walk #62

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

chanced
Copy link
Owner

@chanced chanced commented Jul 10, 2024

So I'm not sure about this pull request at all. The original idea was to add walk_to and walk_from to Resolve / ResolveMut. I'm not crazy about the signature:

    fn walk_to<F, B>(&self, ptr: &Pointer, f: F) -> Result<ControlFlow<B>, Self::Error>
    where
        F: Fn(Component, &Self::Value) -> ControlFlow<B>,
    {
        let _ = self.resolve(ptr)?;
        let root = self.resolve(Pointer::root()).unwrap();
        let mut last = None;
        for component in ptr.components() {
            match component {
                Component::Root => {
                    last = Some(f(Component::Root, root));
                }
                Component::Token {
                    token,
                    index,
                    offset,
                    pointer,
                } => {
                    let value = self.resolve(pointer).unwrap();
                    let tok_len = token.encoded().len();
                    let ctrl_flow = f(
                        Component::Token {
                            token,
                            pointer,
                            index,
                            offset,
                        },
                        value,
                    );
                    if offset + tok_len >= ptr.len() {
                        // last token
                        return Ok(ctrl_flow);
                    }
                    if ctrl_flow.is_break() {
                        return Ok(ctrl_flow);
                    }
                    last = Some(ctrl_flow);
                }
            }
        }
        Ok(last.unwrap())
    }

I'm tempted to rip out Components / Component. Initially I thought this would cut down on a good bit of code in my json schema compiler but I'm doubting whether its worth it.

Would love your feedback when you get time @asmello

@chanced
Copy link
Owner Author

chanced commented Jul 10, 2024

I'm setting this PR aside. I'm just going to push 0.5 with the way things are, including Component / Components. There's room for improvement or removal, not sure which.

I'll leave this one open for now but I don't think walk_to / walk_from are going to make the cut, at least not with the signature above.

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.

1 participant