[fine] Fixup let environment
Also handle circular references in types and environments without exploding, and tweak test output a little bit.
This commit is contained in:
parent
ebad7fe295
commit
308114f8cf
4 changed files with 119 additions and 45 deletions
|
|
@ -66,6 +66,10 @@ impl<'a> SyntaxTree<'a> {
|
|||
self[t].end_pos
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.trees.len()
|
||||
}
|
||||
|
||||
pub fn trees(&self) -> impl Iterator<Item = TreeRef> {
|
||||
(0..self.trees.len()).map(|i| TreeRef::from_index(i))
|
||||
}
|
||||
|
|
@ -164,6 +168,23 @@ impl<'a> Tree<'a> {
|
|||
})
|
||||
.flatten()
|
||||
}
|
||||
|
||||
pub fn dump(&self, tree: &SyntaxTree<'a>, with_positions: bool, output: &mut String) {
|
||||
let _ = write!(output, "{:?}", self.kind);
|
||||
if with_positions {
|
||||
let _ = write!(output, " [{}, {})", self.start_pos, self.end_pos);
|
||||
}
|
||||
let _ = write!(output, "\n");
|
||||
for child in self.children.iter() {
|
||||
child.dump_rec(2, tree, with_positions, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> std::fmt::Debug for Tree<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:?} [{}-{})", self.kind, self.start_pos, self.end_pos)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||
|
|
@ -181,19 +202,6 @@ impl TreeRef {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Tree<'a> {
|
||||
pub fn dump(&self, tree: &SyntaxTree<'a>, with_positions: bool, output: &mut String) {
|
||||
let _ = write!(output, "{:?}", self.kind);
|
||||
if with_positions {
|
||||
let _ = write!(output, " [{}, {})", self.start_pos, self.end_pos);
|
||||
}
|
||||
let _ = write!(output, "\n");
|
||||
for child in self.children.iter() {
|
||||
child.dump_rec(2, tree, with_positions, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Child<'a> {
|
||||
Token(Token<'a>),
|
||||
Tree(TreeRef),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue