File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1693,6 +1693,13 @@ pub fn insert_statement_separators(input: &str) -> String {
16931693 continue ;
16941694 }
16951695
1696+ // Handle line continuation: backslash followed by newline
1697+ if ch == '\\' && i + 1 < len && chars[ i + 1 ] == '\n' {
1698+ // Skip both the backslash and the newline — the next line continues this one
1699+ i += 2 ;
1700+ continue ;
1701+ }
1702+
16961703 // Track nesting depth (including <| |> for associations)
16971704 if ch == '<' && i + 1 < len && chars[ i + 1 ] == '|' {
16981705 depth += 1 ;
Original file line number Diff line number Diff line change @@ -3701,3 +3701,35 @@ mod tilde_infix {
37013701 ) ;
37023702 }
37033703}
3704+
3705+ mod line_continuation {
3706+ use super :: * ;
3707+
3708+ #[ test]
3709+ fn backslash_newline_in_definition ( ) {
3710+ // Backslash at end of line continues the expression on the next line
3711+ assert_eq ! ( interpret( "f[x_] :=\\ \n x^2\n f[5]" ) . unwrap( ) , "25" ) ;
3712+ }
3713+
3714+ #[ test]
3715+ fn backslash_newline_in_expression ( ) {
3716+ assert_eq ! ( interpret( "1 +\\ \n 2 +\\ \n 3" ) . unwrap( ) , "6" ) ;
3717+ }
3718+
3719+ #[ test]
3720+ fn backslash_newline_preserves_function_def ( ) {
3721+ assert_eq ! (
3722+ interpret(
3723+ "ImaginaryQ[u_] :=\\ \n Head[u]===Complex && Re[u]===0\n ImaginaryQ[3 I]"
3724+ )
3725+ . unwrap( ) ,
3726+ "True"
3727+ ) ;
3728+ }
3729+
3730+ #[ test]
3731+ fn backslash_newline_not_in_strings ( ) {
3732+ // Backslash inside strings should NOT be treated as line continuation
3733+ assert_eq ! ( interpret( r#""hello\nworld""# ) . unwrap( ) , r#"hello\nworld"# ) ;
3734+ }
3735+ }
You can’t perform that action at this time.
0 commit comments