Skip to content

Commit

Permalink
Don't crash when using comments in \includepackage (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster authored Aug 14, 2023
1 parent 95fb792 commit ef6e5f1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Don't crash when using comments inside `\include`-like commands ([#919](https://github.com/latex-lsp/texlab/issues/919))

## [5.9.1] - 2023-08-11

### Fixed
Expand Down
9 changes: 6 additions & 3 deletions crates/parser/src/latex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,18 @@ impl<'a> Parser<'a> {

while let Some(kind) = self.peek() {
match kind {
Token::LineComment
| Token::Word
Token::Word
| Token::Eq
| Token::LBrack
| Token::RBrack
| Token::LParen
| Token::RParen
| Token::CommandName(CommandName::Generic) => self.path(),
Token::Whitespace | Token::LineBreak | Token::Comma | Token::Pipe => self.eat(),
Token::Whitespace
| Token::LineBreak
| Token::LineComment
| Token::Comma
| Token::Pipe => self.eat(),
Token::LCurly => self.curly_group_path(),
_ => break,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
source: crates/parser/src/latex.rs
expression: root
input_file: crates/parser/src/test_data/latex/issue_919.txt
---
ROOT@0..217
PREAMBLE@0..217
CLASS_INCLUDE@0..25
COMMAND_NAME@0..14 "\\documentclass"
CURLY_GROUP_WORD_LIST@14..25
L_CURLY@14..15 "{"
KEY@15..22
WORD@15..22 "article"
R_CURLY@22..23 "}"
LINE_BREAK@23..25 "\n\n"
PACKAGE_INCLUDE@25..173
COMMAND_NAME@25..36 "\\usepackage"
CURLY_GROUP_WORD_LIST@36..173
L_CURLY@36..37 "{"
LINE_BREAK@37..38 "\n"
WHITESPACE@38..42 " "
KEY@42..48
WORD@42..48 "lipsum"
COMMA@48..49 ","
WHITESPACE@49..50 " "
COMMENT@50..70 "% provides blindtext"
LINE_BREAK@70..71 "\n"
WHITESPACE@71..75 " "
KEY@75..83
WORD@75..83 "booktabs"
COMMA@83..84 ","
WHITESPACE@84..85 " "
COMMENT@85..110 "% better rules for ta ..."
LINE_BREAK@110..111 "\n"
WHITESPACE@111..115 " "
COMMENT@115..169 "%xcolor % easily defi ..."
LINE_BREAK@169..170 "\n"
R_CURLY@170..171 "}"
LINE_BREAK@171..173 "\n\n"
ENVIRONMENT@173..217
BEGIN@173..194
COMMAND_NAME@173..179 "\\begin"
CURLY_GROUP_WORD@179..194
L_CURLY@179..180 "{"
KEY@180..188
WORD@180..188 "document"
R_CURLY@188..189 "}"
LINE_BREAK@189..190 "\n"
WHITESPACE@190..194 " "
GENERIC_COMMAND@194..202
COMMAND_NAME@194..201 "\\lipsum"
LINE_BREAK@201..202 "\n"
END@202..217
COMMAND_NAME@202..206 "\\end"
CURLY_GROUP_WORD@206..217
L_CURLY@206..207 "{"
KEY@207..215
WORD@207..215 "document"
R_CURLY@215..216 "}"
LINE_BREAK@216..217 "\n"

11 changes: 11 additions & 0 deletions crates/parser/src/test_data/latex/issue_919.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\documentclass{article}

\usepackage{
lipsum, % provides blindtext
booktabs, % better rules for tables
%xcolor % easily define colors with \definecolor{}{}{}
}

\begin{document}
\lipsum
\end{document}

0 comments on commit ef6e5f1

Please sign in to comment.