@@ -13,7 +13,7 @@ fn adapt_pattern(pattern: &mut ast::Pattern<String>, crlf: bool) {
1313 let mut elements = vec ! [ ] ;
1414 for element in & pattern. elements {
1515 match element {
16- ast:: PatternElement :: TextElement { value } => {
16+ ast:: PatternElement :: TextElement { value, .. } => {
1717 let mut start = 0 ;
1818 let len = value. len ( ) ;
1919 for ( i, b) in value. as_bytes ( ) . iter ( ) . enumerate ( ) {
@@ -22,29 +22,53 @@ fn adapt_pattern(pattern: &mut ast::Pattern<String>, crlf: bool) {
2222 if i > start {
2323 let chunk = & value. as_bytes ( ) [ start..=i - 1 ] ;
2424 let value = String :: from_utf8_lossy ( chunk) . to_string ( ) ;
25- elements. push ( ast:: PatternElement :: TextElement { value } ) ;
25+ elements. push ( ast:: PatternElement :: TextElement {
26+ value,
27+ #[ cfg( feature = "spans" ) ]
28+ span : ast:: Span ( start..i) ,
29+ } ) ;
2630 }
31+
2732 elements. push ( ast:: PatternElement :: TextElement {
2833 value : "\n " . to_string ( ) ,
34+ #[ cfg( feature = "spans" ) ]
35+ span : ast:: Span ( i..i + 1 ) ,
2936 } ) ;
3037 } else {
3138 let chunk = & value. as_bytes ( ) [ start..=i] ;
3239 let value = String :: from_utf8_lossy ( chunk) . to_string ( ) ;
33- elements. push ( ast:: PatternElement :: TextElement { value } ) ;
40+ elements. push ( ast:: PatternElement :: TextElement {
41+ value,
42+ #[ cfg( feature = "spans" ) ]
43+ span : ast:: Span ( start..i + 1 ) ,
44+ } ) ;
3445 }
3546 start = i + 1 ;
3647 }
3748 }
49+
3850 if start < len {
3951 let chunk = & value. as_bytes ( ) [ start..len] ;
4052 let value = String :: from_utf8_lossy ( chunk) . to_string ( ) ;
41- elements. push ( ast:: PatternElement :: TextElement { value } ) ;
53+ elements. push ( ast:: PatternElement :: TextElement {
54+ value,
55+ #[ cfg( feature = "spans" ) ]
56+ span : ast:: Span ( start..len) ,
57+ } ) ;
4258 }
4359 }
44- ast:: PatternElement :: Placeable { expression } => {
60+ ast:: PatternElement :: Placeable {
61+ expression,
62+ #[ cfg( feature = "spans" ) ]
63+ span,
64+ } => {
4565 let mut expression = expression. clone ( ) ;
4666 adapt_expression ( & mut expression, crlf) ;
47- elements. push ( ast:: PatternElement :: Placeable { expression } ) ;
67+ elements. push ( ast:: PatternElement :: Placeable {
68+ expression,
69+ #[ cfg( feature = "spans" ) ]
70+ span : span. clone ( ) ,
71+ } ) ;
4872 }
4973 }
5074 }
@@ -58,7 +82,7 @@ fn adapt_expression(expression: &mut ast::Expression<String>, crlf: bool) {
5882 adapt_pattern ( & mut variant. value , crlf) ;
5983 }
6084 }
61- ast:: Expression :: Inline ( _ ) => { }
85+ ast:: Expression :: Inline ( .. ) => { }
6286 }
6387}
6488
0 commit comments