Skip to content

Commit

Permalink
Merge pull request #3775 from Hannah-Sten/ifnextchar-braces
Browse files Browse the repository at this point in the history
Disallow unmatched braces after \@ifnextchar
  • Loading branch information
PHPirates authored Nov 28, 2024
2 parents 5f9ff73 + e4caed9 commit 9ffbf84
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

### Fixed
* Disallow unmatched braces after \@ifnextchar

## [0.9.9-alpha.8] - 2024-11-28

Expand Down
3 changes: 2 additions & 1 deletion src/nl/hannahsten/texifyidea/grammar/LatexLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ WHITE_SPACE={SINGLE_WHITE_SPACE}+
// Commands
BEGIN_TOKEN="\\begin"
END_TOKEN="\\end"
COMMAND_IFNEXTCHAR=\\@ifnextchar.
// All characters after @ifnextchar may be unbalanced, except braces, see https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/3744#issuecomment-2477263416
COMMAND_IFNEXTCHAR=\\@ifnextchar[^{]
COMMAND_TOKEN=\\([a-zA-Z@]+|.|\r)
COMMAND_TOKEN_LATEX3=\\([a-zA-Z@_:0-9]+|.|\r) // _ and : are only LaTeX3 syntax
LATEX3_ON=\\(ExplSyntaxOn|ProvidesExplPackage|ProvidesExplClass|ProvidesExplFile)
Expand Down
2 changes: 2 additions & 0 deletions test/nl/hannahsten/texifyidea/psi/LatexParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class LatexParserTest : BasePlatformTestCase() {
"""
\newcommand{\xyz}{\@ifnextchar[{\@xyz}{\@xyz[default]}}
\def\@xyz[#1]#2{do something with #1 and #2}
\@namedef{#1}{\@ifnextchar{^}{\@nameuse{#1@}}{\@nameuse{#1@}^{}}}
""".trimIndent()
)
myFixture.checkHighlighting()
Expand Down

0 comments on commit 9ffbf84

Please sign in to comment.