Skip to content

Commit 0ae9d18

Browse files
committed
1. Added the keyword #break_search_macro; in situations that require immediate termination of the search for key macros.
1 parent fb478e8 commit 0ae9d18

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ fn search_include_and_replacegroup(
131131
"include_str" => Some(macro_rule_include::<IncludeStr>),
132132
"include_arr" => Some(macro_rule_include::<IncludeArr>),
133133

134+
"break_search_macro" => {
135+
/*
136+
Stop indexing after the given keyword. This saves resources.
137+
*/
138+
139+
if let Some(m_punct2) = iter.next() {
140+
if let TokenTree2::Punct(punct2) = m_punct2 {
141+
if punct2.as_char() == ';' {
142+
let nulltt = make_null_ttree();
143+
144+
*m_ident = nulltt.clone();
145+
*m_punct = nulltt.clone();
146+
*m_punct2 = nulltt;
147+
148+
return SearchGroup::Break;
149+
}
150+
}
151+
}
152+
153+
sg_err! {
154+
return [ident.span()]: "`;` was expected."
155+
}
156+
},
157+
134158
_ => None,
135159
}
136160
};

tests/break.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
use include_tt::include_tt;
3+
4+
#[test]
5+
fn test_empty_tt() {
6+
let str = include_tt! {
7+
#include!("./tests/empty.tt")
8+
/*
9+
The use of this keyword leaves the search for occurrences
10+
needed for replacement.
11+
*/
12+
#break_search_macro;
13+
14+
stringify!(#include!("./tests/empty.tt"))
15+
};
16+
17+
assert_eq!(str, "# include! (\"./tests/empty.tt\")");
18+
}

0 commit comments

Comments
 (0)