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

feature: rust parser: MarkdownCursor.node().walk() should be a MarkdownCursor #170

Open
janWilejan opened this issue Nov 3, 2024 · 1 comment

Comments

@janWilejan
Copy link

tree-sitter-md = { version = "0.3.2", features = ["parser"] }

Node::walk() does not return a MarkdownCursor. This makes it hard to re-visit nodes.

let cursor : MarkdownCursor = ...

// Save a node to come back to
let node = cursor.node();

do_something_with_cursor(&mut cursor);

// Error
let re_visit: MarkdownCursor = node.walk();

Proposed solution:

  • Add struct MarkdownNode as a thin wrapper around Node
    • Deref lets you use all the methods of Node
      impl Deref for MarkdownNode { type Target = Node; ... }
    • Shadow walk to return a MarkdownCursor
      impl MarkdownNode { fn walk(&self) -> MarkdownCursor { ... } }
  • Change MarkdownCursor::node to return MarkdownNode. Or add a new method fn markdown_node(&self) -> MarkdownNode
@ObserverOfTime
Copy link
Member

PR welcome.

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