Skip to main content

xsd_schema/parser/frames/
skip.rs

1// ============================================================================
2// Skip Frame (Error Recovery)
3// ============================================================================
4
5/// Frame for skipping unknown or invalid elements
6pub struct SkipFrame {
7    depth: u32,
8    source: Option<SourceRef>,
9}
10
11impl SkipFrame {
12    pub fn new(source: Option<SourceRef>) -> Self {
13        Self { depth: 0, source }
14    }
15
16    /// Increment depth when entering a child
17    pub fn enter(&mut self) {
18        self.depth += 1;
19    }
20
21    /// Decrement depth when leaving a child
22    pub fn leave(&mut self) -> bool {
23        if self.depth > 0 {
24            self.depth -= 1;
25            false
26        } else {
27            true
28        }
29    }
30}
31
32impl Frame for SkipFrame {
33    fn allows(&self, _local_name: &str, _name_table: &NameTable) -> bool {
34        true // Accept everything when skipping
35    }
36
37    fn allows_attribute(&self, _local_name: &str, _name_table: &NameTable) -> bool {
38        true
39    }
40
41    fn on_child_start(&mut self, _local_name: &str, _name_table: &NameTable) {
42        self.enter();
43    }
44
45    fn attach(&mut self, _child: FrameResult) -> SchemaResult<()> {
46        Ok(())
47    }
48
49    fn finish(self: Box<Self>) -> SchemaResult<FrameResult> {
50        Ok(FrameResult::Skip)
51    }
52
53    fn source(&self) -> Option<&SourceRef> {
54        self.source.as_ref()
55    }
56
57    fn set_foreign_attributes(&mut self, _attrs: Vec<ForeignAttribute>) {}
58
59    fn is_skip_frame(&self) -> bool {
60        true
61    }
62
63    fn on_child_end(&mut self) -> bool {
64        self.leave()
65    }
66}
67