-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.rs
72 lines (58 loc) · 2.17 KB
/
commands.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
mod set;
mod delfile;
mod terminal;
mod intofile;
mod file;
mod raw;
mod note;
mod straw_note;
mod loop_command;
use crate::config::Config;
use crate::preprocessing::PreprocessedObject;
use crate::commands::straw_note::StrawNote;
use crate::commands::raw::Raw;
use crate::commands::note::Note;
use crate::commands::loop_command::LoopCommand;
use crate::commands::file::File;
use crate::commands::intofile::IntoFile;
use crate::commands::terminal::Terminal;
use crate::commands::delfile::DelFile;
use crate::commands::set::Set;
/// This trait is used to create new commands.
pub trait Command {
fn run(
&self,
command: &String,
parameters: &Vec<String>,
text: &String, spaces: &usize,
blocks: &Vec<Box<PreprocessedObject>>,
config: &Config
) -> String;
}
/// This trait is used to create new commands which run in the preprocess section.
pub trait PreprocessedCommand {
fn run(
&self,
command: &String,
parameters: &Vec<String>,
text: &String, spaces: &usize,
blocks: &Vec<Box<PreprocessedObject>>,
preprocessed: Vec<Box<PreprocessedObject>>,
config: &Config
) -> Vec<Box<PreprocessedObject>>;
}
pub fn setup_commands(config: &mut Config) {
config.short_commands.insert("//".to_string(), "@straw_note".to_string());
config.commands.insert("@straw_note".to_string(), Box::new(StrawNote{}));
config.short_commands.insert(".".to_string(), "@raw(false)".to_string());
config.short_commands.insert("*".to_string(), "@raw".to_string());
config.commands.insert("@raw".to_string(), Box::new(Raw{}));
config.short_commands.insert("#".to_string(), "@note".to_string());
config.commands.insert("@note".to_string(), Box::new(Note{}));
config.commands.insert("@loop".to_string(), Box::new(LoopCommand{}));
config.commands.insert("@file".to_string(), Box::new(File{}));
config.commands.insert("@intofile".to_string(), Box::new(IntoFile{}));
config.commands.insert("@delfile".to_string(), Box::new(DelFile{}));
config.commands.insert("@terminal".to_string(), Box::new(Terminal{}));
config.preprocessed_commands.insert("^set".to_string(), Box::new(Set{}));
}