diff options
author | Aleksey Kladov <[email protected]> | 2018-01-01 19:13:04 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-01 19:13:04 +0000 |
commit | 46422f722bdcadbf4462dd5a9c65756434b2d97a (patch) | |
tree | 6b07f7e0ff1a6113630d8f3d66d38291589be03a /src/tree | |
parent | cb362626f326a565aca34c1a11c95dcb7152b798 (diff) |
Parser: first scraches
Diffstat (limited to 'src/tree')
-rw-r--r-- | src/tree/file_builder.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs index eba850fef..da8b8f824 100644 --- a/src/tree/file_builder.rs +++ b/src/tree/file_builder.rs | |||
@@ -64,8 +64,14 @@ impl FileBuilder { | |||
64 | } | 64 | } |
65 | 65 | ||
66 | pub fn finish(self) -> File { | 66 | pub fn finish(self) -> File { |
67 | assert!(self.in_progress.is_empty()); | 67 | assert!( |
68 | assert!(self.pos == (self.text.len() as u32).into()); | 68 | self.in_progress.is_empty(), |
69 | "some nodes in FileBuilder are unfinished" | ||
70 | ); | ||
71 | assert!( | ||
72 | self.pos == (self.text.len() as u32).into(), | ||
73 | "nodes in FileBuilder do not cover the whole file" | ||
74 | ); | ||
69 | File { | 75 | File { |
70 | text: self.text, | 76 | text: self.text, |
71 | nodes: self.nodes, | 77 | nodes: self.nodes, |
@@ -81,11 +87,17 @@ impl FileBuilder { | |||
81 | fn push_child(&mut self, mut child: NodeData) -> NodeIdx { | 87 | fn push_child(&mut self, mut child: NodeData) -> NodeIdx { |
82 | child.parent = Some(self.current_id()); | 88 | child.parent = Some(self.current_id()); |
83 | let id = self.new_node(child); | 89 | let id = self.new_node(child); |
84 | if let Some(sibling) = self.current_sibling() { | 90 | { |
85 | fill(&mut sibling.next_sibling, id); | 91 | |
86 | return id | 92 | let (parent, sibling) = *self.in_progress.last().unwrap(); |
93 | let slot = if let Some(idx) = sibling { | ||
94 | &mut self.nodes[idx].next_sibling | ||
95 | } else { | ||
96 | &mut self.nodes[parent].first_child | ||
97 | }; | ||
98 | fill(slot, id); | ||
87 | } | 99 | } |
88 | fill(&mut self.current_parent().first_child, id); | 100 | self.in_progress.last_mut().unwrap().1 = Some(id); |
89 | id | 101 | id |
90 | } | 102 | } |
91 | 103 | ||