Skip to content

Commit

Permalink
Tweak AST printer
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Feb 2, 2025
1 parent ac3fc97 commit d623f9f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ast/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl FunDecl {
if self.body.is_none() {
buffer.push_str("prim ");
}
self.sig.print(&self.name.node, buffer);
self.sig.print(&self.parent_ty, &self.name.node, buffer);
if let Some(body) = &self.body {
buffer.push_str(" =\n");
for (i, stmt) in body.iter().enumerate() {
Expand Down Expand Up @@ -298,8 +298,11 @@ impl Type {
}

impl FunSig {
pub fn print(&self, name: &Id, buffer: &mut String) {
buffer.push_str("fn ");
pub fn print(&self, parent_ty: &Option<L<Id>>, name: &Id, buffer: &mut String) {
if let Some(parent_ty) = parent_ty {
buffer.push_str(&parent_ty.node);
buffer.push('.');
}
buffer.push_str(name);
print_context(&self.context, buffer);
buffer.push('(');
Expand Down Expand Up @@ -985,7 +988,7 @@ impl Display for Type {
impl Display for FunSig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut s = String::new();
self.print(&SmolStr::new(""), &mut s);
self.print(&None, &SmolStr::new(""), &mut s);
f.write_str(&s)
}
}
Expand Down

0 comments on commit d623f9f

Please sign in to comment.