@@ -12,26 +12,29 @@ use crate::{
12
12
derive:: { DeriveError , DeriveResult } ,
13
13
options:: {
14
14
records:: fields:: { ChildOpts , FieldValueGroupOpts } ,
15
- AllowUnknown , ElementOrder , FieldWithOpts , IgnoreWhitespace ,
15
+ AllowUnknown , ElementOrder , FieldWithOpts , IgnoreComments , IgnoreWhitespace ,
16
16
} ,
17
17
} ;
18
18
19
19
pub struct SeqLoopAccessor {
20
20
allow_unknown_children : AllowUnknown ,
21
21
order : ElementOrder ,
22
22
ignore_whitespace : IgnoreWhitespace ,
23
+ ignore_comments : IgnoreComments ,
23
24
}
24
25
25
26
impl SeqLoopAccessor {
26
27
pub fn new (
27
28
allow_unknown_children : AllowUnknown ,
28
29
order : ElementOrder ,
29
30
ignore_whitespace : IgnoreWhitespace ,
31
+ ignore_comments : IgnoreComments ,
30
32
) -> Self {
31
33
Self {
32
34
allow_unknown_children,
33
35
order,
34
36
ignore_whitespace,
37
+ ignore_comments,
35
38
}
36
39
}
37
40
@@ -79,8 +82,8 @@ impl SeqLoopAccessor {
79
82
let Self {
80
83
allow_unknown_children,
81
84
order,
82
-
83
85
ignore_whitespace,
86
+ ignore_comments,
84
87
} = self ;
85
88
86
89
let whitespace_ty: syn:: Type = parse_quote ! { :: xmlity:: types:: utils:: Whitespace } ;
@@ -98,6 +101,21 @@ impl SeqLoopAccessor {
98
101
}
99
102
} ;
100
103
104
+ let comment_ty: syn:: Type = parse_quote ! { :: xmlity:: value:: XmlComment } ;
105
+
106
+ let ignore_comments_expression: Vec < Stmt > = match ignore_comments {
107
+ IgnoreComments :: Any => {
108
+ parse_quote ! {
109
+ if let Ok ( Some ( _) ) = :: xmlity:: de:: SeqAccess :: next_element:: <#comment_ty>( #seq_access) {
110
+ continue ;
111
+ }
112
+ }
113
+ }
114
+ IgnoreComments :: None => {
115
+ vec ! [ ]
116
+ }
117
+ } ;
118
+
101
119
let ignored_any_ty: syn:: Type = parse_quote ! { :: xmlity:: types:: utils:: IgnoredAny } ;
102
120
103
121
match order {
@@ -245,6 +263,7 @@ impl SeqLoopAccessor {
245
263
Ok ( parse_quote ! {
246
264
loop {
247
265
#( #ignore_whitespace_expression) *
266
+ #( #ignore_comments_expression) *
248
267
#( #if_statements) *
249
268
}
250
269
} )
@@ -317,6 +336,7 @@ impl SeqLoopAccessor {
317
336
Ok ( parse_quote ! {
318
337
loop {
319
338
#( #ignore_whitespace_expression) *
339
+ #( #ignore_comments_expression) *
320
340
#( #field_visits) *
321
341
#( #skip_unknown) *
322
342
}
0 commit comments