forked from SpaceManiac/SpacemanDMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotation.rs
More file actions
95 lines (77 loc) · 2.51 KB
/
annotation.rs
File metadata and controls
95 lines (77 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Data structures for the parser to output mappings from input ranges to AST
//! elements at those positions.
use interval_tree::{IntervalTree, RangePairIter, RangeInclusive, range};
use super::Location;
use super::ast::*;
pub type Iter<'a> = RangePairIter<'a, Location, Annotation>;
#[derive(Debug)]
pub enum Annotation {
// contextual information
TreeBlock(Vec<Ident>),
TreePath(bool, Vec<Ident>),
TypePath(TypePath),
Variable(Vec<Ident>),
ProcHeader(Vec<Ident>, usize),
ProcBody(Vec<Ident>, usize),
LocalVarScope(VarType, Ident),
// local information about a specific token
UnscopedCall(Ident),
UnscopedVar(Ident),
ScopedCall(Vec<Ident>, Ident),
ScopedVar(Vec<Ident>, Ident),
ParentCall, // ..
ReturnVal, // .
InSequence(usize), // where in TreePath or TypePath is this ident
// a macro is called here, which is defined at this location
MacroDefinition(Ident),
MacroUse(String, Location),
Include(std::path::PathBuf),
Resource(std::path::PathBuf),
// error annotations, mostly for autocompletion
ScopedMissingIdent(Vec<Ident>), // when a . is followed by a non-ident
IncompleteTypePath(TypePath, PathOp),
IncompleteTreePath(bool, Vec<Ident>),
ProcArguments(Vec<Ident>, String, usize), // Vec empty for unscoped call
ProcArgument(usize), // where in the prog arguments we are
}
#[derive(Debug)]
pub struct AnnotationTree {
tree: IntervalTree<Location, Annotation>,
len: usize,
}
impl Default for AnnotationTree {
fn default() -> Self {
AnnotationTree {
tree: IntervalTree::new(),
len: 0,
}
}
}
impl AnnotationTree {
pub fn insert(&mut self, place: std::ops::Range<Location>, value: Annotation) {
self.tree.insert(range(place.start, place.end.pred()), value);
self.len += 1;
}
pub fn merge(&mut self, other: AnnotationTree) {
self.len += other.len;
self.tree.merge(other.tree);
}
pub fn len(&self) -> usize {
self.len
}
pub fn is_empty(&self) -> bool {
self.len == 0
}
pub fn iter(&self) -> Iter {
self.tree.iter()
}
pub fn get_location(&self, loc: Location) -> Iter {
self.tree.range(range(loc.pred(), loc))
}
pub fn get_range(&self, place: std::ops::Range<Location>) -> Iter {
self.tree.range(range(place.start, place.end.pred()))
}
pub fn get_range_raw(&self, place: RangeInclusive<Location>) -> Iter {
self.tree.range(place)
}
}