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
Performing tree traversal, I noticed that an empty document will produce a DOC_START_TOKEN + BLOCK_EMPTY, both with a range of start = 0 and length = 0.
This defeats tree traversal implementations in token_first_child_in_range, token_last_child_in_range, token_child_for_offset that can't descend into empty tokens.
I've been working with this more intensely the past months and to my surprise found that an offset and sub-range based check work well like so:
Does a character range _R_ include offset _O_? A check for inclusion entails that the range is not empty and the offset falls chiefly inside it: R.start <= O && R.start + R.length > O
Does a character range _Ra_ contain character range _Rb_? A check for subrange overlap will falsely (= my argument) reject the same range iff both are empty. (0..<0) and (0..<0) would not overlap at the moment.
For the subrange check I found that this works fine (again, to my surprise), including equal ranges:
the current approach can't traverse empty trees, as a DOC_START_TOKEN + BLOCK_EMPTY with length of 0 cannot be drilled down into;
the end-of-file position is always past everything: past the document range, and past any of its tokens, so you never know the context of the blinking cursor at the very end
The text was updated successfully, but these errors were encountered:
DivineDominion
changed the title
token_first_child_in_range, token_last_child_in_range, token_child_for_offset can't traverse empty trees
token_first_child_in_range, token_last_child_in_range, token_child_for_offset limited at the end of the document
Jul 6, 2024
This is another use of the AST as a data source:
Performing tree traversal, I noticed that an empty document will produce a
DOC_START_TOKEN
+BLOCK_EMPTY
, both with a range ofstart = 0
andlength = 0
.This defeats tree traversal implementations in
token_first_child_in_range
,token_last_child_in_range
,token_child_for_offset
that can't descend into empty tokens.I've been working with this more intensely the past months and to my surprise found that an offset and sub-range based check work well like so:
Does a character range _R_ include offset _O_?
A check for inclusion entails that the range is not empty and the offset falls chiefly inside it:R.start <= O && R.start + R.length > O
Does a character range _Ra_ contain character range _Rb_?
A check for subrange overlap will falsely (= my argument) reject the same range iff both are empty. (0..<0) and (0..<0) would not overlap at the moment.For the subrange check I found that this works fine (again, to my surprise), including equal ranges:
Consequences:
DOC_START_TOKEN
+BLOCK_EMPTY
with length of 0 cannot be drilled down into;The text was updated successfully, but these errors were encountered: