Skip to content

Commit e2fc2a3

Browse files
committed
1. Final refactoring.
1 parent 02c2aff commit e2fc2a3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,16 @@ pub (crate) mod macros {
115115
fn search_include_and_replacegroup(
116116
iter: &mut IterMut<'_, TokenTree2>,
117117
) -> SearchGroup {
118-
while let Some(m_punct) = iter.next() {
118+
'sbegin: while let Some(m_punct) = iter.next() {
119119
match m_punct {
120120
TokenTree2::Punct(punct) => {
121121
if punct.as_char() == '#' {
122122
if let Some(m_ident) = iter.next() {
123123
if let TokenTree2::Ident(ident) = m_ident {
124124
let macro_fn = {
125-
match ident.to_string().as_str() {
125+
let str_ident = ident.to_string();
126+
127+
match str_ident.as_str() {
126128
"include" | "include_tt" => macro_rule_include::<IncludeTt>,
127129
"include_and_fix_unknown_start_token" | "include_tt_and_fix_unknown_start_token" => macro_rule_include::<IncludeTtAndFixUnkStartToken>,
128130

@@ -148,12 +150,18 @@ fn search_include_and_replacegroup(
148150
*m_punct = nulltt.clone();
149151
*m_punct2 = nulltt.clone();
150152
*m_group = result;
153+
154+
continue 'sbegin;
151155
}
152156
}
153157
}
154158
// autoskip
155159
}
156160
}
161+
162+
sg_err! {
163+
return [ident.span()]: "Unknown macro, expected `include(...)`, `include_tt(...)`, `include_and_fix_unknown_start_token(...)`, `include_tt_and_fix_unknown_start_token(...)`, `include_str(...)`, `include_arr(...)`"
164+
}
157165
}
158166
}
159167
}
@@ -164,7 +172,7 @@ fn search_include_and_replacegroup(
164172
group,
165173
|mut iter| search_include_and_replacegroup(&mut iter),
166174
) {
167-
SearchGroup::Break => continue,
175+
SearchGroup::Break => continue 'sbegin,
168176
result @ SearchGroup::Error(..) => return result,
169177
},
170178
_ => {},

src/macros/include.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl BehMacroArg0 {
6565

6666
/// Easily include trees from a file in your
6767
/// final custom macro code.
68-
pub (crate) enum IncludeTt {}
68+
pub enum IncludeTt {}
6969

7070
impl BehMacroInclude for IncludeTt {
7171
type Result = TokenTree2;
@@ -90,7 +90,7 @@ impl BehMacroInclude for IncludeTt {
9090
|sspath| load_file_and_automake_tree_fn(
9191
sspath,
9292

93-
|_| {},
93+
|_| {}, /* skip_prepare */
9494
|fs_tt| {
9595
let ett = match fs_tt {
9696
Some(a) => TokenStream2::from_iter(a.into_iter()),
@@ -118,7 +118,7 @@ impl BehMacroInclude for IncludeTt {
118118
/// invalid tokens breaking the parser.
119119
///
120120
/// (Implemented specifically for C-like languages using `\` as a line code string)
121-
pub (crate) enum IncludeTtAndFixUnkStartToken {}
121+
pub enum IncludeTtAndFixUnkStartToken {}
122122

123123
impl BehMacroInclude for IncludeTtAndFixUnkStartToken {
124124
type Result = TokenTree2;
@@ -219,7 +219,7 @@ impl BehMacroInclude for IncludeTtAndFixUnkStartToken {
219219

220220
/// Includes the entire file as a single line,
221221
/// similar to 'include_str'.
222-
pub (crate) enum IncludeStr {}
222+
pub enum IncludeStr {}
223223

224224
impl BehMacroInclude for IncludeStr {
225225
type Result = TokenTree2;
@@ -260,7 +260,7 @@ impl BehMacroInclude for IncludeStr {
260260

261261
/// Includes the entire file as a binary array,
262262
/// similar to 'include_str'.
263-
pub (crate) enum IncludeArr {}
263+
pub enum IncludeArr {}
264264

265265
impl BehMacroInclude for IncludeArr {
266266
type Result = TokenTree2;

0 commit comments

Comments
 (0)