Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Dec 8, 2024
1 parent 2058231 commit 1865f8e
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 58 deletions.
9 changes: 9 additions & 0 deletions crates/ast/src/ast/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ impl UserDefinableOperator {
}
}

impl fmt::Display for UserDefinableOperator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.to_op() {
Either::Left(op) => f.write_str(op.to_str()),
Either::Right(op) => f.write_str(op.to_str()),
}
}
}

/// A contract, abstract contract, interface, or library definition:
/// `contract Foo is Bar("foo"), Baz { ... }`.
///
Expand Down
18 changes: 18 additions & 0 deletions crates/ast/src/ast/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ pub struct Lit {
pub kind: LitKind,
}

impl fmt::Display for Lit {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Self { kind, symbol, span: _ } = self;
match kind {
LitKind::Str(StrKind::Str, _) => write!(f, "\"{symbol}\""),
LitKind::Str(StrKind::Unicode, _) => write!(f, "unicode\"{symbol}\""),
LitKind::Str(StrKind::Hex, _) => write!(f, "hex\"{symbol}\""),
LitKind::Number(_)
| LitKind::Rational(_)
| LitKind::Err(_)
| LitKind::Address(_)
| LitKind::Bool(_) => {
write!(f, "{symbol}")
}
}
}
}

/// A kind of literal.
#[derive(Clone, Debug)]
pub enum LitKind {
Expand Down
Loading

0 comments on commit 1865f8e

Please sign in to comment.