Skip to content

Commit

Permalink
Allow paths with brackets in LaTeX parser
Browse files Browse the repository at this point in the history
See #639.
  • Loading branch information
pfoerster committed May 31, 2022
1 parent 2c8ba68 commit fa8778e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/syntax/latex/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ impl<'a> Parser<'a> {
fn curly_group_path(&mut self) {
self.builder.start_node(CURLY_GROUP_WORD.into());
self.eat();
while matches!(self.peek(), Some(WORD)) {
while matches!(self.peek(), Some(WORD | L_BRACK | R_BRACK)) {
self.path();
}

Expand All @@ -866,17 +866,20 @@ impl<'a> Parser<'a> {
self.builder.start_node(CURLY_GROUP_WORD_LIST.into());
self.eat();

while self
.peek()
.filter(|&kind| {
matches!(
kind,
LINE_BREAK | WHITESPACE | COMMENT | WORD | COMMA | EQUALITY_SIGN
)
})
.is_some()
{
if self.peek() == Some(WORD) {
while self.peek().map_or(false, |kind| {
matches!(
kind,
LINE_BREAK
| WHITESPACE
| COMMENT
| WORD
| COMMA
| EQUALITY_SIGN
| L_BRACK
| R_BRACK
)
}) {
if matches!(self.peek(), Some(WORD | L_BRACK | R_BRACK)) {
self.path();
} else {
self.eat();
Expand All @@ -890,11 +893,12 @@ impl<'a> Parser<'a> {
fn path(&mut self) {
self.builder.start_node(KEY.into());
self.eat();
while self
.peek()
.filter(|&kind| matches!(kind, WHITESPACE | COMMENT | WORD | EQUALITY_SIGN))
.is_some()
{
while self.peek().map_or(false, |kind| {
matches!(
kind,
WHITESPACE | COMMENT | WORD | EQUALITY_SIGN | L_BRACK | R_BRACK
)
}) {
self.eat();
}

Expand Down Expand Up @@ -1582,6 +1586,11 @@ mod tests {
assert_debug_snapshot!(setup(r#"\input{foo/bar.tex}"#));
}

#[test]
fn test_latex_input_path_with_brackets() {
assert_debug_snapshot!(setup(r#"\input{foo[bar].tex}"#));
}

#[test]
fn test_biblatex_include_simple() {
assert_debug_snapshot!(setup(r#"\addbibresource{foo/bar.bib}"#));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
source: src/syntax/latex/parser.rs
assertion_line: 1591
expression: "setup(r#\"\\input{foo[bar].tex}\"#)"
---
ROOT@0..20
PREAMBLE@0..20
LATEX_INCLUDE@0..20
LATEX_INCLUDE_NAME@0..6 "\\input"
CURLY_GROUP_WORD_LIST@6..20
L_CURLY@6..7 "{"
KEY@7..19
WORD@7..10 "foo"
L_BRACK@10..11 "["
WORD@11..14 "bar"
R_BRACK@14..15 "]"
WORD@15..19 ".tex"
R_CURLY@19..20 "}"

0 comments on commit fa8778e

Please sign in to comment.