scanner: fix string slash line breaks error
							parent
							
								
									cd5dccd855
								
							
						
					
					
						commit
						e0e064ff08
					
				|  | @ -728,3 +728,14 @@ fn test_split_into_lines() { | ||||||
| 		assert line == line_content | 		assert line == line_content | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | fn test_string_literal_with_backslash(){ | ||||||
|  |     a := 'Hello\ | ||||||
|  |           World' | ||||||
|  |     assert a == 'HelloWorld' | ||||||
|  | 
 | ||||||
|  | 	b := 'One\ | ||||||
|  | 		  Two\ | ||||||
|  | 		  Three' | ||||||
|  | 	assert b == 'OneTwoThree' | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -900,13 +900,31 @@ fn (s mut Scanner) ident_string() string { | ||||||
| 	if s.is_inside_string { | 	if s.is_inside_string { | ||||||
| 		end++ | 		end++ | ||||||
| 	} | 	} | ||||||
| 	if start > s.pos {} | 	if start <= s.pos { | ||||||
| 	else { | 		if s.text[start..end].contains('\\\n') { | ||||||
|  | 			lit = trim_slash_line_break(s.text[start..end]) | ||||||
|  | 		} else { | ||||||
| 			lit = s.text[start..end] | 			lit = s.text[start..end] | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| 	return lit | 	return lit | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | fn trim_slash_line_break(s string) string { | ||||||
|  | 	mut start := 0 | ||||||
|  | 	mut ret_str := s | ||||||
|  | 	for { | ||||||
|  | 		idx := ret_str.index_after('\\\n', start) | ||||||
|  | 		if idx != -1 { | ||||||
|  | 			ret_str = ret_str[..idx] + ret_str[idx+2..].trim_left(' \n\t\v\f\r') | ||||||
|  | 			start = idx | ||||||
|  | 		} else { | ||||||
|  | 			break | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return ret_str | ||||||
|  | } | ||||||
|  | 
 | ||||||
| fn (s mut Scanner) ident_char() string { | fn (s mut Scanner) ident_char() string { | ||||||
| 	start := s.pos | 	start := s.pos | ||||||
| 	slash := `\\` | 	slash := `\\` | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue