Skip to content

Commit

Permalink
Fix parsing acronym definitions
Browse files Browse the repository at this point in the history
See #813.
  • Loading branch information
pfoerster committed Nov 12, 2022
1 parent f7b619d commit 2c6bdf3
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/parser/latex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,15 +1108,15 @@ impl<'a> Parser<'a> {

if self.lexer.peek() == Some(L_CURLY) {
self.curly_group_word();
} else {
self.builder.token(MISSING.into(), "");
}

if self.lexer.peek() == Some(L_BRACK) {
self.brack_group();
}

for _ in 0..2 {
if self.lexer.peek() == Some(L_CURLY) {
self.curly_group();
} else {
self.builder.token(MISSING.into(), "");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/latex/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ enum CommandNameToken {

#[token("\\newacronym")]
#[token("\\newacro")]
#[token("\\newacrodef")]
#[token("\\acrodef")]
#[token("\\acro")]
#[token("\\newacroindefinite")]
#[token("\\acrodefindefinite")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
source: src/parser/latex.rs
expression: root
---
ROOT@0..35
PREAMBLE@0..35
ACRONYM_DEFINITION@0..35
ACRONYM_DEFINITION_NAME@0..5 "\\acro"
CURLY_GROUP_WORD@5..10
L_CURLY@5..6 "{"
KEY@6..9
WORD@6..9 "fps"
R_CURLY@9..10 "}"
BRACK_GROUP@10..15
L_BRACK@10..11 "["
TEXT@11..14
WORD@11..14 "FPS"
R_BRACK@14..15 "]"
CURLY_GROUP@15..35
L_CURLY@15..16 "{"
TEXT@16..33
WORD@16..22 "Frames"
WHITESPACE@22..23 " "
WORD@23..26 "per"
WHITESPACE@26..27 " "
WORD@27..33 "Second"
R_CURLY@33..34 "}"
LINE_BREAK@34..35 "\n"

1 change: 1 addition & 0 deletions src/parser/test_data/latex/glossary/acronym_package.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\acro{fps}[FPS]{Frames per Second}
14 changes: 14 additions & 0 deletions tests/integration/lsp/text_document/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ fn acronym_ref_open_brace() -> Result<()> {
Ok(())
}

#[test]
fn acronym_package_ref() -> Result<()> {
assert_items!(complete(
r#"
%TEX main.tex
%SRC \acrodef{fpsLabel}[FPS]{Frames per Second}
%SRC \ac{f
%CUR ^
%1.1 ^"#
)?);

Ok(())
}

#[test]
fn glossary_ref_simple() -> Result<()> {
assert_items!(complete(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: tests/integration/lsp/text_document/completion.rs
expression: "complete(r#\"\n%TEX main.tex\n%SRC \\acrodef{fpsLabel}[FPS]{Frames per Second}\n%SRC \\ac{f\n%CUR ^\n%1.1 ^\"#)?"
---
[
{
"data": "[data]",
"kind": 1,
"label": "fpsLabel",
"preselect": false,
"sortText": "[sortText]",
"textEdit": {
"range": "[range]",
"newText": "fpsLabel"
}
}
]

0 comments on commit 2c6bdf3

Please sign in to comment.