Skip to content

Commit

Permalink
Fix parsing wrong superscripts like 10^10 (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster authored Jun 22, 2024
1 parent cd82eb4 commit 6b572f0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add missing citation commands: `\citeA`, `\citeR`, `\citeS`, `\citeyearR` ([#94](https://github.com/latex-lsp/tree-sitter-latex/issues/94))
- Let `\declaretheorem` accept multiple environment names ([texlab/#1075](https://github.com/latex-lsp/texlab/issues/1075))
- Fix parsing wrong superscripts like `10^10` ([#107](https://github.com/latex-lsp/tree-sitter-latex/issues/107))

## [0.4.0] - 2024-04-01

Expand Down
6 changes: 4 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,18 @@ module.exports = grammar({

operator: $ => choice('+', '-', '*', '/', '<', '>', '!', '|', ':', "'"),

letter: $ => /[^\\%\{\}\$\#_\^]/,

subscript: $ =>
seq(
'_',
field('subscript', choice($.curly_group, $.word, $.generic_command)),
field('subscript', choice($.curly_group, $.letter, $.command_name)),
),

superscript: $ =>
seq(
'^',
field('superscript', choice($.curly_group, $.word, $.generic_command)),
field('superscript', choice($.curly_group, $.letter, $.command_name)),
),

//--- Key / Value
Expand Down
28 changes: 22 additions & 6 deletions test/corpus/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,11 @@ Let
(text
(word)
(superscript
(word))
(letter))
(operator)
(word)
(superscript
(word)))
(letter)))
(text_mode
(curly_group
(text
Expand All @@ -497,11 +497,12 @@ Let
(text
(word)
(superscript
(word))
(letter))
(operator)
(word)
(superscript
(word)))
(letter))
(word))
(end
(curly_group_text
(text
Expand Down Expand Up @@ -756,6 +757,21 @@ r \big|_0^a
(command_name))
(operator)
(subscript
(word))
(letter))
(superscript
(word))))
(letter))))

================================================================================
tree-sitter-latex (Issue #107) | subscript
================================================================================

10^10

--------------------------------------------------------------------------------

(source_file
(text
(word)
(superscript
(letter))
(word)))
4 changes: 2 additions & 2 deletions test/corpus/math.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,6 @@ Foo_{bar}^2
(subscript
(curly_group
(text
(word))))
(word))))
(superscript
(word))))
(letter))))

0 comments on commit 6b572f0

Please sign in to comment.