diff options
author | Norbert Preining <norbert@preining.info> | 2019-12-03 03:01:24 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-12-03 03:01:24 +0000 |
commit | b8d4bb76703bcb15578e2b23c5d256532180b894 (patch) | |
tree | bedd1df7a00521a2bd986b3c0289d6556a59e39b /support/texlab/src/syntax/latex/glossary.rs | |
parent | 02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff) |
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/src/syntax/latex/glossary.rs')
-rw-r--r-- | support/texlab/src/syntax/latex/glossary.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/support/texlab/src/syntax/latex/glossary.rs b/support/texlab/src/syntax/latex/glossary.rs new file mode 100644 index 0000000000..14f87ef130 --- /dev/null +++ b/support/texlab/src/syntax/latex/glossary.rs @@ -0,0 +1,58 @@ +use super::ast::*; +use crate::syntax::language::*; +use crate::syntax::text::SyntaxNode; +use lsp_types::Range; +use std::sync::Arc; + +#[derive(Debug, PartialEq, Eq, Clone)] +pub struct LatexGlossaryEntry { + pub command: Arc<LatexCommand>, + pub label_index: usize, + pub kind: LatexGlossaryEntryKind, +} + +impl SyntaxNode for LatexGlossaryEntry { + fn range(&self) -> Range { + self.command.range() + } +} + +impl LatexGlossaryEntry { + pub fn label(&self) -> &LatexToken { + self.command.extract_word(self.label_index).unwrap() + } + + fn parse(commands: &[Arc<LatexCommand>]) -> Vec<Self> { + let mut entries = Vec::new(); + for command in commands { + for LatexGlossaryEntryDefinitionCommand { + name, + label_index, + kind, + } in &LANGUAGE_DATA.glossary_entry_definition_commands + { + if command.name.text() == name && command.has_word(*label_index) { + entries.push(Self { + command: Arc::clone(&command), + label_index: *label_index, + kind: *kind, + }); + } + } + } + entries + } +} + +#[derive(Debug, PartialEq, Eq, Clone)] +pub struct LatexGlossaryInfo { + pub entries: Vec<LatexGlossaryEntry>, +} + +impl LatexGlossaryInfo { + pub fn parse(commands: &[Arc<LatexCommand>]) -> Self { + Self { + entries: LatexGlossaryEntry::parse(commands), + } + } +} |