You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, i have been using rowan in my own project, it works absolutely great. However, when parsing something like a markdown file, i run into issues with text ranges because it assumes the root node starts at the start of the source. Which means i need to offset every single node, token, or element's range i make. It would be great if i could make a syntax node and tell rowan the range is actually offset by a certain amount, i tried to implement this myself but i ran into a good amount of issues, including:
A lot of things internally rely on range, this could probably be solved by making a raw_range internal method
There may be conflicts with how rowan uses the range to find stuff inside of green nodes, this could probably also be solved by the above.
Text would stay the same, as the green node will still have the right text, only text range of parent and children would be affected.
The text was updated successfully, but these errors were encountered:
One possible way of kludging an offset together with the current API is to just put an extra green node in front with the desired offset length. Ofc, that requires a string of that length to back it, so it's not a great solution.
It in theory wouldn't be a difficult change to at a base offset to the syntax tree. In theory, "just:"
Change Kind::Root(GreenNode) to Kind::Root { node: GreenNode, offset: TextSize }
See if that changes the size of Kind. If so, investigate finagling the definition to re-add a niche to keep the size the same. (Idea: child index probably can be guaranteed to fit in u16.)
Update all the places matching Kind::Root(green) to Kind::Root { node: green, .. }, as well as the root constructor to take a root offset. (Or make a new constructor that takes an offset, and the existing one uses a zero offset.)
Update SyntaxNode::text_range to match the inner kind and read the root offset, rather than using the as_child helper. Probably add a SyntaxNode::offset(&self) -> TextSize helper.
That should be all that's necessary to add a root offset to the syntax tree. That also should make it possible to "reroot" syntax trees, pulling out a subtree so the rest can potentially be reclaimed, though I don't know how useful that'd be in practice.
Hello, i have been using rowan in my own project, it works absolutely great. However, when parsing something like a markdown file, i run into issues with text ranges because it assumes the root node starts at the start of the source. Which means i need to offset every single node, token, or element's range i make. It would be great if i could make a syntax node and tell rowan the range is actually offset by a certain amount, i tried to implement this myself but i ran into a good amount of issues, including:
raw_range
internal methodText would stay the same, as the green node will still have the right text, only text range of parent and children would be affected.
The text was updated successfully, but these errors were encountered: