Make Debug of some ast types more compact
This commit is contained in:
parent
ad91e3b3fb
commit
e7e4ca76fc
1 changed files with 36 additions and 3 deletions
39
src/ast.rs
39
src/ast.rs
|
|
@ -1,11 +1,19 @@
|
||||||
#[derive(Debug, Clone)]
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Ident(pub String);
|
pub struct Ident(pub String);
|
||||||
|
|
||||||
|
impl fmt::Debug for Ident {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "i#{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Positive number literal.
|
/// Positive number literal.
|
||||||
///
|
///
|
||||||
/// Possible bases are binary, decimal, hexadecimal. Underscores can be inserted
|
/// Possible bases are binary, decimal, hexadecimal. Underscores can be inserted
|
||||||
/// before and after any digit.
|
/// before and after any digit.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub enum NumLit {
|
pub enum NumLit {
|
||||||
/// - `0b_0001_1011`
|
/// - `0b_0001_1011`
|
||||||
/// - `0b10`
|
/// - `0b10`
|
||||||
|
|
@ -20,6 +28,16 @@ pub enum NumLit {
|
||||||
Hex(i64, String),
|
Hex(i64, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for NumLit {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Bin(_, str) => write!(f, "0b{str}"),
|
||||||
|
Self::Dec(_, str) => write!(f, "{str}"),
|
||||||
|
Self::Hex(_, str) => write!(f, "0x{str}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TableLitElem {
|
pub enum TableLitElem {
|
||||||
/// `a`
|
/// `a`
|
||||||
|
|
@ -36,7 +54,7 @@ pub struct TableLit {
|
||||||
pub trailing_comma: bool,
|
pub trailing_comma: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Lit {
|
pub enum Lit {
|
||||||
/// `nil`
|
/// `nil`
|
||||||
Nil,
|
Nil,
|
||||||
|
|
@ -57,6 +75,21 @@ pub enum Lit {
|
||||||
Table(TableLit),
|
Table(TableLit),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Lit {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::Nil => write!(f, "l#nil"),
|
||||||
|
Self::Bool(b) => write!(f, "l#{b:?}"),
|
||||||
|
Self::Num(n) => write!(f, "l#{n:?}"),
|
||||||
|
Self::String(s) => write!(f, "l#{s:?}"),
|
||||||
|
Self::Table(t) => {
|
||||||
|
write!(f, "l#")?;
|
||||||
|
t.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TableConstrElem {
|
pub enum TableConstrElem {
|
||||||
/// See [`TableLitElem`].
|
/// See [`TableLitElem`].
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue