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/finder.rs | |
parent | 02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff) |
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/src/syntax/latex/finder.rs')
-rw-r--r-- | support/texlab/src/syntax/latex/finder.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/support/texlab/src/syntax/latex/finder.rs b/support/texlab/src/syntax/latex/finder.rs new file mode 100644 index 0000000000..b59388dc07 --- /dev/null +++ b/support/texlab/src/syntax/latex/finder.rs @@ -0,0 +1,74 @@ +use super::ast::*; +use crate::range::RangeExt; +use crate::syntax::text::SyntaxNode; +use lsp_types::Position; +use std::sync::Arc; + +#[derive(Debug, PartialEq, Eq, Clone)] +pub enum LatexNode { + Root(Arc<LatexRoot>), + Group(Arc<LatexGroup>), + Command(Arc<LatexCommand>), + Text(Arc<LatexText>), + Comma(Arc<LatexComma>), + Math(Arc<LatexMath>), +} + +#[derive(Debug)] +pub struct LatexFinder { + pub position: Position, + pub results: Vec<LatexNode>, +} + +impl LatexFinder { + pub fn new(position: Position) -> Self { + Self { + position, + results: Vec::new(), + } + } +} + +impl LatexVisitor for LatexFinder { + fn visit_root(&mut self, root: Arc<LatexRoot>) { + if root.range().contains(self.position) { + self.results.push(LatexNode::Root(Arc::clone(&root))); + LatexWalker::walk_root(self, root); + } + } + + fn visit_group(&mut self, group: Arc<LatexGroup>) { + if group.range.contains(self.position) { + self.results.push(LatexNode::Group(Arc::clone(&group))); + LatexWalker::walk_group(self, group); + } + } + + fn visit_command(&mut self, command: Arc<LatexCommand>) { + if command.range.contains(self.position) { + self.results.push(LatexNode::Command(Arc::clone(&command))); + LatexWalker::walk_command(self, command); + } + } + + fn visit_text(&mut self, text: Arc<LatexText>) { + if text.range.contains(self.position) { + self.results.push(LatexNode::Text(Arc::clone(&text))); + LatexWalker::walk_text(self, text); + } + } + + fn visit_comma(&mut self, comma: Arc<LatexComma>) { + if comma.range().contains(self.position) { + self.results.push(LatexNode::Comma(Arc::clone(&comma))); + LatexWalker::walk_comma(self, comma); + } + } + + fn visit_math(&mut self, math: Arc<LatexMath>) { + if math.range().contains(self.position) { + self.results.push(LatexNode::Math(Arc::clone(&math))); + LatexWalker::walk_math(self, math); + } + } +} |