Dotted pair structures

This commit is contained in:
Erin 2022-07-26 19:29:56 +02:00 committed by ondra05
parent b7240fa1c1
commit f28d454841
2 changed files with 6 additions and 0 deletions

View file

@ -43,6 +43,7 @@ impl<T: Hash> Hash for Spanned<T> {
pub enum Expr<'a> { pub enum Expr<'a> {
List(Vec<Spanned<Self>>), List(Vec<Spanned<Self>>),
Vector(Vec<Spanned<Self>>), Vector(Vec<Spanned<Self>>),
Pair((Box<Spanned<Self>>, Box<Spanned<Self>>)),
Quote(Box<Spanned<Self>>), Quote(Box<Spanned<Self>>),
Symbol(Cow<'a, str>), Symbol(Cow<'a, str>),
Keyword(Cow<'a, str>), Keyword(Cow<'a, str>),
@ -58,6 +59,7 @@ impl<'a> Display for Expr<'a> {
write!(f, "#")?; write!(f, "#")?;
fmt_list(f, vec) fmt_list(f, vec)
} }
Self::Pair((l, r)) => write!(f, "{l} . {r}"),
Self::Quote(expr) => write!(f, "'{expr}"), Self::Quote(expr) => write!(f, "'{expr}"),
Self::Symbol(sym) => write!(f, "{sym}"), Self::Symbol(sym) => write!(f, "{sym}"),
Self::Keyword(kw) => write!(f, ":{kw}"), Self::Keyword(kw) => write!(f, ":{kw}"),

View file

@ -11,6 +11,9 @@ pub enum Token<'a> {
#[token(")")] #[token(")")]
RightParen, RightParen,
#[token(".")]
Dot,
#[token("'")] #[token("'")]
Quote, Quote,
@ -51,6 +54,7 @@ impl<'a> Display for Token<'a> {
match self { match self {
Token::LeftParen => write!(f, "("), Token::LeftParen => write!(f, "("),
Token::RightParen => write!(f, ")"), Token::RightParen => write!(f, ")"),
Token::Dot => write!(f, "."),
Token::Quote => write!(f, "'"), Token::Quote => write!(f, "'"),
Token::Octothrope => write!(f, "#"), Token::Octothrope => write!(f, "#"),
Token::String(s) => write!(f, "\"{s}\""), Token::String(s) => write!(f, "\"{s}\""),