Parser: first scraches

This commit is contained in:
Aleksey Kladov
2018-01-01 22:13:04 +03:00
parent cb362626f3
commit 46422f722b
9 changed files with 97 additions and 17 deletions

View File

@@ -64,8 +64,14 @@ impl FileBuilder {
}
pub fn finish(self) -> File {
assert!(self.in_progress.is_empty());
assert!(self.pos == (self.text.len() as u32).into());
assert!(
self.in_progress.is_empty(),
"some nodes in FileBuilder are unfinished"
);
assert!(
self.pos == (self.text.len() as u32).into(),
"nodes in FileBuilder do not cover the whole file"
);
File {
text: self.text,
nodes: self.nodes,
@@ -81,11 +87,17 @@ impl FileBuilder {
fn push_child(&mut self, mut child: NodeData) -> NodeIdx {
child.parent = Some(self.current_id());
let id = self.new_node(child);
if let Some(sibling) = self.current_sibling() {
fill(&mut sibling.next_sibling, id);
return id
{
let (parent, sibling) = *self.in_progress.last().unwrap();
let slot = if let Some(idx) = sibling {
&mut self.nodes[idx].next_sibling
} else {
&mut self.nodes[parent].first_child
};
fill(slot, id);
}
fill(&mut self.current_parent().first_child, id);
self.in_progress.last_mut().unwrap().1 = Some(id);
id
}