From f28d4548414376d24fb170e7cab63819a08c46b3 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 26 Jul 2022 19:29:56 +0200 Subject: [PATCH] Dotted pair structures --- src/syntax/ast.rs | 2 ++ src/syntax/lexer.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 16d9425..6bfc236 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -43,6 +43,7 @@ impl Hash for Spanned { pub enum Expr<'a> { List(Vec>), Vector(Vec>), + Pair((Box>, Box>)), Quote(Box>), Symbol(Cow<'a, str>), Keyword(Cow<'a, str>), @@ -58,6 +59,7 @@ impl<'a> Display for Expr<'a> { write!(f, "#")?; fmt_list(f, vec) } + Self::Pair((l, r)) => write!(f, "{l} . {r}"), Self::Quote(expr) => write!(f, "'{expr}"), Self::Symbol(sym) => write!(f, "{sym}"), Self::Keyword(kw) => write!(f, ":{kw}"), diff --git a/src/syntax/lexer.rs b/src/syntax/lexer.rs index c4f96c6..e84617b 100644 --- a/src/syntax/lexer.rs +++ b/src/syntax/lexer.rs @@ -11,6 +11,9 @@ pub enum Token<'a> { #[token(")")] RightParen, + #[token(".")] + Dot, + #[token("'")] Quote, @@ -51,6 +54,7 @@ impl<'a> Display for Token<'a> { match self { Token::LeftParen => write!(f, "("), Token::RightParen => write!(f, ")"), + Token::Dot => write!(f, "."), Token::Quote => write!(f, "'"), Token::Octothrope => write!(f, "#"), Token::String(s) => write!(f, "\"{s}\""),