-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_identifier.rs
More file actions
72 lines (64 loc) · 2.58 KB
/
Copy pathindex_identifier.rs
File metadata and controls
72 lines (64 loc) · 2.58 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
use std::collections::HashMap;
#[derive(Default, Debug, Clone)]
pub struct IdentifierIndex {
data_types: HashMap<String, i16>,
flow_types: HashMap<String, i16>,
runtime_flow_types: HashMap<String, i16>,
functions: HashMap<String, i16>,
function_definitions: HashMap<String, i16>,
module_configuration_definitions: HashMap<String, i16>,
}
fn normalize(s: &str) -> String {
s.trim().to_ascii_lowercase()
}
impl IdentifierIndex {
pub fn insert_data_type(&mut self, name: &str, id: i16) -> Option<i16> {
self.data_types.insert(normalize(name), id)
}
pub fn insert_flow_type(&mut self, name: &str, id: i16) -> Option<i16> {
self.flow_types.insert(normalize(name), id)
}
pub fn insert_runtime_flow_type(&mut self, name: &str, id: i16) -> Option<i16> {
self.runtime_flow_types.insert(normalize(name), id)
}
pub fn insert_function(&mut self, name: &str, id: i16) -> Option<i16> {
self.functions.insert(normalize(name), id)
}
pub fn insert_function_definition(&mut self, name: &str, id: i16) -> Option<i16> {
self.function_definitions.insert(normalize(name), id)
}
pub fn insert_module_configuration_definition(&mut self, name: &str, id: i16) -> Option<i16> {
self.module_configuration_definitions
.insert(normalize(name), id)
}
pub fn has_data_type(&self, name: &str, except: Option<i16>) -> bool {
self.data_types
.get(&normalize(name))
.map(|found| except.map(|e| *found != e).unwrap_or(true))
.unwrap_or(false)
}
pub fn has_flow_type(&self, name: &str, except: Option<i16>) -> bool {
self.flow_types
.get(&normalize(name))
.map(|found| except.map(|e| *found != e).unwrap_or(true))
.unwrap_or(false)
}
pub fn has_runtime_flow_type(&self, name: &str, except: Option<i16>) -> bool {
self.runtime_flow_types
.get(&normalize(name))
.map(|found| except.map(|e| *found != e).unwrap_or(true))
.unwrap_or(false)
}
pub fn has_function_definition(&self, name: &str, except: Option<i16>) -> bool {
self.function_definitions
.get(&normalize(name))
.map(|found| except.map(|e| *found != e).unwrap_or(true))
.unwrap_or(false)
}
pub fn has_module_configuration_definition(&self, name: &str, except: Option<i16>) -> bool {
self.module_configuration_definitions
.get(&normalize(name))
.map(|found| except.map(|e| *found != e).unwrap_or(true))
.unwrap_or(false)
}
}