1
1
use std:: borrow:: Cow ;
2
2
use std:: process:: ExitCode ;
3
- use std:: sync:: OnceLock ;
3
+ use std:: sync:: LazyLock ;
4
4
use std:: { env, fs} ;
5
5
6
6
use regex:: { Regex , RegexBuilder } ;
@@ -151,8 +151,7 @@ impl CommandKind {
151
151
}
152
152
}
153
153
154
- static LINE_PATTERN : OnceLock < Regex > = OnceLock :: new ( ) ;
155
- fn line_pattern ( ) -> Regex {
154
+ static LINE_PATTERN : LazyLock < Regex > = LazyLock :: new ( || {
156
155
RegexBuilder :: new (
157
156
r#"
158
157
//@\s+
@@ -165,7 +164,19 @@ fn line_pattern() -> Regex {
165
164
. unicode ( true )
166
165
. build ( )
167
166
. unwrap ( )
168
- }
167
+ } ) ;
168
+
169
+ static DEPRECATED_LINE_PATTERN : LazyLock < Regex > = LazyLock :: new ( || {
170
+ RegexBuilder :: new (
171
+ r#"
172
+ //\s+@
173
+ "# ,
174
+ )
175
+ . ignore_whitespace ( true )
176
+ . unicode ( true )
177
+ . build ( )
178
+ . unwrap ( )
179
+ } ) ;
169
180
170
181
fn print_err ( msg : & str , lineno : usize ) {
171
182
eprintln ! ( "Invalid command: {} on line {}" , msg, lineno)
@@ -184,21 +195,23 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> {
184
195
for ( lineno, line) in file. split ( '\n' ) . enumerate ( ) {
185
196
let lineno = lineno + 1 ;
186
197
187
- let cap = match LINE_PATTERN . get_or_init ( line_pattern) . captures ( line) {
188
- Some ( c) => c,
189
- None => continue ,
198
+ if DEPRECATED_LINE_PATTERN . is_match ( line) {
199
+ print_err ( "Deprecated command syntax, replace `// @` with `//@ `" , lineno) ;
200
+ errors = true ;
201
+ continue ;
202
+ }
203
+
204
+ let Some ( cap) = LINE_PATTERN . captures ( line) else {
205
+ continue ;
190
206
} ;
191
207
192
- let negated = cap. name ( "negated" ) . unwrap ( ) . as_str ( ) == "!" ;
208
+ let negated = & cap[ "negated" ] == "!" ;
193
209
194
210
let args_str = & cap[ "args" ] ;
195
- let args = match shlex:: split ( args_str) {
196
- Some ( args) => args,
197
- None => {
198
- print_err ( & format ! ( "Invalid arguments to shlex::split: `{args_str}`" , ) , lineno) ;
199
- errors = true ;
200
- continue ;
201
- }
211
+ let Some ( args) = shlex:: split ( args_str) else {
212
+ print_err ( & format ! ( "Invalid arguments to shlex::split: `{args_str}`" , ) , lineno) ;
213
+ errors = true ;
214
+ continue ;
202
215
} ;
203
216
204
217
if let Some ( ( kind, path) ) = CommandKind :: parse ( & cap[ "cmd" ] , negated, & args) {
0 commit comments