This commit is contained in:
2026-04-17 18:51:12 -04:00
parent 2f91e454dd
commit b3f77076d4
20 changed files with 244 additions and 192 deletions
+21 -9
View File
@@ -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)
}
}