diff options
author | Norbert Preining <norbert@preining.info> | 2022-02-27 03:01:13 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-02-27 03:01:13 +0000 |
commit | a911d39178540078c8ff5bc880418478d7433c40 (patch) | |
tree | f23b6a0f6bf9f548e7e43cf2405e864eba99b21e /support/texlab/src/syntax/latex/parser.rs | |
parent | 740a11f29a3551babe3d7edbb57ac3baa2280a3f (diff) |
CTAN sync 202202270301
Diffstat (limited to 'support/texlab/src/syntax/latex/parser.rs')
-rw-r--r-- | support/texlab/src/syntax/latex/parser.rs | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/support/texlab/src/syntax/latex/parser.rs b/support/texlab/src/syntax/latex/parser.rs index a7fe3342f8..fcca6771a2 100644 --- a/support/texlab/src/syntax/latex/parser.rs +++ b/support/texlab/src/syntax/latex/parser.rs @@ -74,7 +74,7 @@ impl<'a> Parser<'a> { fn trivia(&mut self) { while self .peek() - .filter(|&kind| matches!(kind, WHITESPACE | COMMENT)) + .filter(|&kind| matches!(kind, LINE_BREAK | WHITESPACE | COMMENT)) .is_some() { self.eat(); @@ -96,7 +96,7 @@ impl<'a> Parser<'a> { fn content(&mut self, context: ParserContext) { match self.peek().unwrap() { - WHITESPACE | COMMENT => self.eat(), + LINE_BREAK | WHITESPACE | COMMENT => self.eat(), L_CURLY if context.allow_environment => self.curly_group(), L_CURLY => self.curly_group_without_environments(), L_BRACK | L_PAREN => self.mixed_group(), @@ -162,7 +162,7 @@ impl<'a> Parser<'a> { while self .peek() .filter(|&kind| { - matches!(kind, WHITESPACE | COMMENT | WORD | COMMA) + matches!(kind, LINE_BREAK | WHITESPACE | COMMENT | WORD | COMMA) && (context.allow_comma || kind != COMMA) }) .is_some() @@ -211,6 +211,9 @@ impl<'a> Parser<'a> { Some(WORD) => { self.key(); } + Some(kind) if kind.is_command_name() => { + self.content(ParserContext::default()); + } Some(_) | None => { self.builder.token(MISSING.into(), ""); } @@ -225,7 +228,7 @@ impl<'a> Parser<'a> { while self .peek() - .filter(|&kind| matches!(kind, WHITESPACE | COMMENT | WORD | COMMA)) + .filter(|&kind| matches!(kind, LINE_BREAK | WHITESPACE | COMMENT | WORD | COMMA)) .is_some() { if self.peek() == Some(WORD) { @@ -340,6 +343,8 @@ impl<'a> Parser<'a> { { self.eat(); } + + self.trivia(); self.builder.finish_node(); } @@ -381,7 +386,7 @@ impl<'a> Parser<'a> { self.builder.start_node(KEY_VALUE_BODY.into()); while let Some(kind) = self.peek() { match kind { - WHITESPACE | COMMENT => self.eat(), + LINE_BREAK | WHITESPACE | COMMENT => self.eat(), WORD => { self.key_value_pair(); if self.peek() == Some(COMMA) { @@ -433,7 +438,7 @@ impl<'a> Parser<'a> { self.eat(); while let Some(kind) = self.peek() { match kind { - WHITESPACE | COMMENT => self.eat(), + LINE_BREAK | WHITESPACE | COMMENT => self.eat(), L_CURLY => self.curly_group(), L_BRACK | L_PAREN => self.mixed_group(), _ => break, @@ -932,6 +937,10 @@ impl<'a> Parser<'a> { if self.lexer.peek() == Some(L_BRACK) { self.brack_group_word(); + + if self.lexer.peek() == Some(L_BRACK) { + self.brack_group(); + } } if self.lexer.peek() == Some(L_CURLY) { @@ -1566,6 +1575,11 @@ mod tests { } #[test] + fn test_command_definition_optional() { + assert_debug_snapshot!(setup(r#"\newcommand{\foo}[1][def]{#1}"#)); + } + + #[test] fn test_command_definition_no_argc() { assert_debug_snapshot!(setup(r#"\newcommand{\foo}{foo}"#)); } @@ -1708,4 +1722,9 @@ mod tests { r#"\DeclareAcronym{eg}{short = e.g,long = for example,tag = abbrev}"# )); } + + #[test] + fn test_label_definition_line_break() { + assert_debug_snapshot!(setup("\\label{hello\nworld}")); + } } |