@@ -403,8 +403,15 @@ fn compile_address_range(
403403 }
404404 }
405405
406+ // zero-address r command check
406407 if is_line0 && n_addr == 1 {
407- return compilation_error ( lines, line, "address 0 requires a second address" ) ;
408+ // after retrieval of first address, subsequent spaces
409+ // are consumed unconditionally. By now, the position
410+ // must be in non-whitespace character or eol.
411+ let next_cmd = if line. eol ( ) { '\0' } else { line. current ( ) } ;
412+ if !matches ! ( next_cmd, 'r' ) {
413+ return compilation_error ( lines, line, "address 0 requires a second address" ) ;
414+ }
408415 }
409416
410417 Ok ( n_addr)
@@ -1804,6 +1811,51 @@ mod tests {
18041811 ScriptCharProvider :: new ( "" )
18051812 }
18061813
1814+ #[ test]
1815+ fn test_zero_addr_r_accepted ( ) {
1816+ for input in [ "0r" , "0 r" ] {
1817+ let ( lines, mut chars) = make_providers ( input) ;
1818+ let mut cmd = Rc :: new ( RefCell :: new ( Command :: default ( ) ) ) ;
1819+ let n_addr = compile_address_range ( & lines, & mut chars, & mut cmd, & ctx ( ) ) . unwrap ( ) ;
1820+
1821+ assert_eq ! ( n_addr, 1 ) ;
1822+ assert ! ( matches!( cmd. borrow( ) . addr1, Some ( Address :: Line ( 0 ) ) ) ) ;
1823+ assert_eq ! ( chars. current( ) , 'r' ) ;
1824+ }
1825+ }
1826+
1827+ // Zero-address with no commands
1828+ #[ test]
1829+ fn test_zero_addr_no_commands ( ) {
1830+ let ( lines, mut chars) = make_providers ( "0" ) ;
1831+ let mut cmd = Rc :: new ( RefCell :: new ( Command :: default ( ) ) ) ;
1832+ let result = compile_address_range ( & lines, & mut chars, & mut cmd, & ctx ( ) ) ;
1833+
1834+ assert ! ( result. is_err( ) ) ;
1835+ assert ! (
1836+ result
1837+ . unwrap_err( )
1838+ . to_string( )
1839+ . contains( "address 0 requires a second addres" )
1840+ ) ;
1841+ }
1842+
1843+ // Zero-address with a command other than 'r' must still be rejected.
1844+ #[ test]
1845+ fn test_zero_addr_non_r_rejected ( ) {
1846+ let ( lines, mut chars) = make_providers ( "0p" ) ;
1847+ let mut cmd = Rc :: new ( RefCell :: new ( Command :: default ( ) ) ) ;
1848+ let result = compile_address_range ( & lines, & mut chars, & mut cmd, & ctx ( ) ) ;
1849+
1850+ assert ! ( result. is_err( ) ) ;
1851+ assert ! (
1852+ result
1853+ . unwrap_err( )
1854+ . to_string( )
1855+ . contains( "address 0 requires a second addres" )
1856+ ) ;
1857+ }
1858+
18071859 #[ test]
18081860 fn test_compile_sequence_empty_input ( ) {
18091861 let mut provider = make_line_provider ( & [ ] ) ;
0 commit comments