11use std:: borrow:: Cow ;
22use std:: process:: ExitCode ;
3- use std:: sync:: OnceLock ;
3+ use std:: sync:: LazyLock ;
44use std:: { env, fs} ;
55
66use regex:: { Regex , RegexBuilder } ;
@@ -151,8 +151,7 @@ impl CommandKind {
151151 }
152152}
153153
154- static LINE_PATTERN : OnceLock < Regex > = OnceLock :: new ( ) ;
155- fn line_pattern ( ) -> Regex {
154+ static LINE_PATTERN : LazyLock < Regex > = LazyLock :: new ( || {
156155 RegexBuilder :: new (
157156 r#"
158157 //@\s+
@@ -165,7 +164,19 @@ fn line_pattern() -> Regex {
165164 . unicode ( true )
166165 . build ( )
167166 . 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+ } ) ;
169180
170181fn print_err ( msg : & str , lineno : usize ) {
171182 eprintln ! ( "Invalid command: {} on line {}" , msg, lineno)
@@ -184,21 +195,23 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> {
184195 for ( lineno, line) in file. split ( '\n' ) . enumerate ( ) {
185196 let lineno = lineno + 1 ;
186197
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 ;
190206 } ;
191207
192- let negated = cap. name ( "negated" ) . unwrap ( ) . as_str ( ) == "!" ;
208+ let negated = & cap[ "negated" ] == "!" ;
193209
194210 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 ;
202215 } ;
203216
204217 if let Some ( ( kind, path) ) = CommandKind :: parse ( & cap[ "cmd" ] , negated, & args) {
0 commit comments