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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use alloc::{borrow::ToOwned, boxed::Box, string::ToString, vec};
use ellie_core::{
definite::{definers, definers::DefinerCollecting},
error,
};
use ellie_tokenizer::syntax::items::definers::FunctionType;
impl super::DefinerParserProcessor for FunctionType {
fn process(
&self,
options: &mut super::DefinerParserProcessorOptions,
) -> Result<DefinerCollecting, alloc::vec::Vec<ellie_core::error::Error>> {
let mut errors = vec![];
let mut found = DefinerCollecting::Dynamic;
let deep_search_result = options.parser.deep_search(
options.page_id,
"function".to_string(),
options.ignore_hash,
vec![],
0,
None,
);
if deep_search_result.found {
match deep_search_result.found_item {
crate::parser::DeepSearchItems::Class(_) => {
let params = self
.params
.iter()
.filter_map(|x| match x.process(options) {
Ok(e) => Some(e),
Err(err) => {
errors.extend(err);
None
}
})
.collect();
let returning = match self.returning.process(options) {
Ok(e) => Some(e),
Err(e) => {
errors.extend(e);
None
}
};
if errors.is_empty() {
found = DefinerCollecting::Function(definers::FunctionType {
params,
returning: Box::new(returning.unwrap()),
});
} else {
return Err(errors);
}
}
_ => match deep_search_result.found_pos {
Some(ref_pos) => {
let mut error = error::error_list::ERROR_S45.clone().build_with_path(
vec![error::ErrorBuildField {
key: "token".to_string(),
value: "function".to_string(),
}],
alloc::format!("{}:{}:{}", file!().to_owned(), line!(), column!()),
options
.parser
.find_page(options.page_id)
.unwrap()
.path
.clone(),
self.pos,
);
error.reference_message = "Defined here".to_string();
error.reference_block = Some((ref_pos, deep_search_result.found_page.path));
errors.push(error);
}
None => {
errors.push(
error::error_list::ERROR_S45.clone().build_with_path(
vec![error::ErrorBuildField {
key: "token".to_string(),
value: "function".to_string(),
}],
alloc::format!("{}:{}:{}", file!().to_owned(), line!(), column!()),
options
.parser
.find_page(options.page_id)
.unwrap()
.path
.clone(),
self.pos,
),
);
}
},
}
} else {
errors.push(
error::error_list::ERROR_S6.clone().build_with_path(
vec![error::ErrorBuildField {
key: "token".to_string(),
value: "function".to_string(),
}],
alloc::format!("{}:{}:{}", file!().to_owned(), line!(), column!()),
options
.parser
.find_page(options.page_id)
.unwrap()
.path
.clone(),
self.pos,
),
);
}
if !errors.is_empty() {
Err(errors)
} else {
Ok(found)
}
}
}