latex-lsp / tree-sitter-latex

LaTeX grammar for tree-sitter
MIT License
87 stars 21 forks source link

incorrect parsing of sub- and superscripts #107

Closed underscore-j closed 3 weeks ago

underscore-j commented 3 months ago

Subscripts _ and superscripts ^ apply only to the next character (or text in curly braces).

This parser, however, treats the entire next "word" as the sub- or superscript, which can lead to incorrect syntax highlighting or concealing.

(Granted, this probably doesn't occur very often, as spaces, operators and commands cause the word to end anyway. It came up for me when replacing spaces with ~, which are treated as part of a word. Proper parsing could also help spot mistakes such as writing 10^10.)

underscore-j commented 3 months ago

The opposite happens when an operator appears in a sub- or superscript, like r^+. The operator is not treated as part of the superscript, but as its next sibling. Instead, the child of the superscript is an empty generic_command.