work
This commit is contained in:
@@ -1,26 +1,38 @@
|
||||
use super::Token;
|
||||
use crate::io::Span;
|
||||
|
||||
pub struct Lit {
|
||||
pub ty: LitTy,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum Lit {
|
||||
pub enum LitTy {
|
||||
Number(String),
|
||||
Bool(bool),
|
||||
String(String),
|
||||
Unit,
|
||||
}
|
||||
|
||||
impl From<Lit> for Token {
|
||||
fn from(value: Lit) -> Self {
|
||||
impl From<LitTy> for Token {
|
||||
fn from(value: LitTy) -> Self {
|
||||
Self::Lit(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for LitTy {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Number(n) => write!(f, "{n}"),
|
||||
Self::Bool(b) => write!(f, "{b}"),
|
||||
Self::String(s) => write!(f, "\"{s}\""),
|
||||
Self::Unit => write!(f, "()"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Lit {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Lit::Number(n) => write!(f, "{n}"),
|
||||
Lit::Bool(b) => write!(f, "{b}"),
|
||||
Lit::String(s) => write!(f, "\"{s}\""),
|
||||
Lit::Unit => write!(f, "()"),
|
||||
}
|
||||
self.ty.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user