Context-sensitive state information

Will it be possible, using Lezer, to record the “local state at the cursor” and update it dynamically? What I mean is, suppose you have an XML document, say with a lot of tags. Now suppose we are in the editor (say CodeMirror) and the XML document and cursor position look as follows:

<remark>
...
</remark>

<remark>
...   * Cursor is here
</remark>

It would be nice to know that, at the current cursor position, we are inside the second remark environment. Is that possible with Lezer and/or CodeMirror?

I have in mind eventually implementing the procedure

XML stylesheet + XML document --> HTML document

directly in CodeMirror + Lezer in this way. (Or is there a better way?)

If you have the syntax tree, you can use resolve to get information about the node at a given position, and then use its parent/childBefore/childAfter properties to get contextual information. The interface doesn’t expose child indices directly, since this type of tree also includes comments and such as nodes, making child indices rather useless.

Ok. Seems a bit inefficient to have to traverse the tree again to get this information. But I guess that is the modularity paradigm.