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
/***************************************
Auteur : Pierre Aubert
Mail : pierre.aubert@lapp.in2p3.fr
Licence : CeCILL-C
****************************************/
///Describe a language, extension, filenames, comments, etc
#[derive(Debug,Clone,Default)]
pub struct PLanguage{
///Say if the highlighter will display line number
p_is_line_number: bool,
///All characters which define a token
p_token_charset: String,
///Vector of accepted extensions for highlighting this particular language
p_vec_extention: Vec<String>,
///Vector of accepted filenames for highlithing this particular language (CMakeList.txt for cmake, Dockerfile for docker, etc)
p_vec_filename: Vec<String>,
///Definition of a single line comment in this language
p_single_line_comment: String,
///Beginning of a multi-line comment in this language
p_multi_line_comment_begin: String,
///Ending of a multi-line comment in this language
p_multi_line_comment_end: String,
///Say if the current parser has an escape char, false otherwise
p_is_escape_char: bool,
///Code example for the highlighting
p_example: String,
}
impl PLanguage{
///Constructor of a PLanguage
/// # Parameters
/// - `is_line_number` : true if the highlighter will display line number
/// - `token_charset` : charset which contains all characters which composed a token
pub fn new(is_line_number: bool, token_charset: String) -> Self {
PLanguage {
p_is_line_number: is_line_number,
p_token_charset: token_charset.clone(),
p_vec_extention: Default::default(),
p_vec_filename: Default::default(),
p_single_line_comment: String::from(""),
p_multi_line_comment_begin: String::from(""),
p_multi_line_comment_end: String::from(""),
p_is_escape_char: false,
p_example: String::from(""),
}
}
///Set the vector of extensions
/// # Parameters
/// - `vec_extention` : vector of accepted extensions for highlighting this particular language
pub fn set_vec_extension(&mut self, vec_extention: &Vec<String>){
self.p_vec_extention = vec_extention.clone();
}
///Set the vector of accepted filenames for this language (CMakeLists.txt for CMake, Dockerfile for Docker, etc)
/// # Parameters
/// - `vec_filename` : vector of accepted filenames for highlithing this particular language (CMakeList.txt for cmake, Dockerfile for docker, etc)
pub fn set_vec_filename(&mut self, vec_filename: &Vec<String>){
self.p_vec_filename = vec_filename.clone();
}
///Set the single line comment
/// # Parameters
/// - `single_line_comment` : string which defines a single line comment in the language
pub fn set_single_line_comment(&mut self, single_line_comment: &String){
self.p_single_line_comment = single_line_comment.clone();
}
///Set the beginning of a multiline comment
/// # Parameters
/// - `multi_line_comment_begin` : beginning of a multi-line comment in this language
pub fn set_multi_line_comment_begin(&mut self, multi_line_comment_begin: &String){
self.p_multi_line_comment_begin = multi_line_comment_begin.clone();
}
///Set the ending of a multiline comment
/// # Parameters
/// - `multi_line_comment_end` : ending of a multi-line comment in this language
pub fn set_multi_line_comment_end(&mut self, multi_line_comment_end: &String){
self.p_multi_line_comment_end = multi_line_comment_end.clone();
}
///Set there is an escape char
/// # Parameters
/// - `is_escape_char` : true if there is an escape char
pub fn set_is_escape_char(&mut self, is_escape_char: bool){
self.p_is_escape_char = is_escape_char;
}
///Set the example of the PLanguage
/// # Parameters
/// - `example` : example of the PLanguage
pub fn set_example(&mut self, example: &String){
self.p_example = example.clone();
}
///Say if the language needs line numbers
/// # Returns
/// True if the language needs line numbers, false otherwise
pub fn get_is_line_number(&self) -> bool{
self.p_is_line_number
}
///Get the token characters set to be used to define a token
/// # Returns
/// Token characters set to be used to define a token
pub fn get_token_charset(&self) -> &String{
&self.p_token_charset
}
///Get the vector of extensions accepted by the language
/// # Returns
/// Vector of extensions accepted by the language
pub fn get_vec_extention(&self) -> &Vec<String>{
&self.p_vec_extention
}
///Get the vector of filenames accepted by the language
/// # Returns
/// Vector of filenames accepted by the language (CMakeLists.txt for CMake, Dockerfile for Docker, etc)
pub fn get_vec_filename(&self) -> &Vec<String>{
&self.p_vec_filename
}
///Get the single line comment of the language
/// # Returns
/// Single line comment of the language
pub fn get_single_line_comment(&self) -> &String{
&self.p_single_line_comment
}
///Get the beginning of the multi lines comment of the language
/// # Returns
/// Beginning of the multi lines comment of the language
pub fn get_multi_line_comment_begin(&self) -> &String{
&self.p_multi_line_comment_begin
}
///Get the ending of the multi lines comment of the language
/// # Returns
/// Ending of the multi lines comment of the language
pub fn get_multi_line_comment_end(&self) -> &String{
&self.p_multi_line_comment_end
}
///Get if there is an escape char
/// # Returns
/// True if there is an escape char
pub fn get_is_escape_char(&self) -> bool{
self.p_is_escape_char
}
///Set the example of the PLanguage
/// # Returns
/// Example of the PLanguage
pub fn get_example(&self) -> &String{
&self.p_example
}
}