-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.rs
148 lines (133 loc) · 3.41 KB
/
mod.rs
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// #[cfg(feature = "engine-extensions")]
// pub mod ext__default;
#[cfg(feature = "engine-extensions")]
pub mod ext_macro;
#[cfg(feature = "engine-extensions")]
pub mod ext_text;
use crate::engine::Document;
use crate::engine::Environment;
#[allow(dead_code)]
#[derive(Debug)]
pub enum Value {
Text(String),
Symbol(String),
Number(f64),
Vector(Vec<Value>),
True,
False,
Void,
}
#[derive(Debug)]
pub struct Context<'a> {
pub begining: bool,
pub result: Option<Value>,
pub doc: &'a Document<'a>,
pub doc_position: usize,
pub env: &'a mut Environment,
pub source: &'a str,
pub fct_name: &'a str,
pub args: Vec<Value>,
}
impl<'a> Context<'a> {
pub fn new(
doc: &'a Document,
doc_position: usize,
env: &'a mut Environment,
source: &'a str,
) -> Self {
Context {
begining: true,
result: None,
doc: doc,
doc_position: doc_position,
env: env,
source: source,
fct_name: &source[0..0],
args: vec![],
}
}
}
#[cfg_attr(not(feature = "engine-extensions"), allow(dead_code))]
#[derive(Debug)]
pub struct Helper {
module_name: &'static str,
module_description: &'static str,
functions: Vec<HelperFunction>,
}
#[cfg_attr(not(feature = "engine-extensions"), allow(dead_code))]
impl Helper {
pub fn display(&self) {
println!(
"
♦ Extension '{}'
{}",
self.module_name, self.module_description
);
for f in self.functions.iter() {
f.display();
}
println!("");
}
}
#[cfg_attr(not(feature = "engine-extensions"), allow(dead_code))]
#[derive(Debug)]
pub struct HelperFunction {
function_name: &'static str,
function_description: &'static str,
function_can_pipe: bool,
function_args: &'static str,
}
#[cfg_attr(not(feature = "engine-extensions"), allow(dead_code))]
impl HelperFunction {
fn display(&self) {
println!(
"
↪ function '{}' (pipe : {})
description : {}
args : {}",
self.function_name,
if self.function_can_pipe { "yes" } else { "no" },
self.function_description,
self.function_args,
);
}
}
#[cfg(feature = "engine-extensions")]
mod optional_feature {
// use crate::engine::extensions::ext__default;
use crate::engine::extensions::ext_macro;
use crate::engine::extensions::ext_text;
use crate::engine::extensions::Context;
pub fn execute<'a>(module: &str, context: &mut Context) -> Option<String> {
match module {
// m if m == ext__default::MODULE_NAME => ext_default::execute(context),
m if m == ext_macro::MODULE_NAME => ext_macro::execute(context),
m if m == ext_text::MODULE_NAME => ext_text::execute(context),
m => Some(format!(
"Extension '{}' not found (--help-extensions argument may assist you)",
m
)),
}
}
pub fn help() {
// ext__default::help().display();
ext_macro::help().display();
ext_text::help().display();
}
}
#[cfg(not(feature = "engine-extensions"))]
mod optional_feature {
use crate::engine::extensions::Context;
pub fn execute<'a>(_module: &str, _context: &mut Context) -> Option<String> {
Some("Extensions are not available in this version of the engine".to_string())
}
pub fn help() {
println!("Extensions are not available in this version of the engine")
}
}
pub fn execute<'a>(module: &str, context: &mut Context) -> Option<String> {
optional_feature::execute(module, context)
}
pub fn help() {
optional_feature::help();
}