Simplified AST

This commit is contained in:
Erin 2022-07-24 21:50:35 +02:00 committed by ondra05
parent bb50f1e450
commit afef6bf6af
2 changed files with 0 additions and 7 deletions

View file

@ -12,10 +12,8 @@ pub enum Expr<'a> {
Map(Vec<(Self, Self)>), Map(Vec<(Self, Self)>),
Symbol(Cow<'a, str>), Symbol(Cow<'a, str>),
Keyword(Cow<'a, str>), Keyword(Cow<'a, str>),
Bool(bool),
Number(OrderedFloat<f64>), Number(OrderedFloat<f64>),
String(Cow<'a, str>), String(Cow<'a, str>),
Nil,
} }
impl<'a> Display for Expr<'a> { impl<'a> Display for Expr<'a> {
@ -31,10 +29,8 @@ impl<'a> Display for Expr<'a> {
), ),
Self::Symbol(sym) => write!(f, "{sym}"), Self::Symbol(sym) => write!(f, "{sym}"),
Self::Keyword(kw) => write!(f, ":{kw}"), Self::Keyword(kw) => write!(f, ":{kw}"),
Self::Bool(b) => write!(f, "{b}"),
Self::Number(n) => write!(f, "{n}"), Self::Number(n) => write!(f, "{n}"),
Self::String(s) => write!(f, "\"{s}\""), Self::String(s) => write!(f, "\"{s}\""),
Self::Nil => write!(f, "nil"),
} }
} }
} }

View file

@ -12,9 +12,6 @@ pub fn read(src: &str) -> Result<Vec<Expr>, Vec<Simple<Token<'_>>>> {
fn parser<'a>() -> impl Parser<Token<'a>, Vec<Expr<'a>>, Error = Simple<Token<'a>>> { fn parser<'a>() -> impl Parser<Token<'a>, Vec<Expr<'a>>, Error = Simple<Token<'a>>> {
recursive(|expr| { recursive(|expr| {
let atom = select! { let atom = select! {
Token::Symbol("true") => Expr::Bool(true),
Token::Symbol("false") => Expr::Bool(false),
Token::Symbol("nil") => Expr::Nil,
Token::Symbol(s) => Expr::Symbol(s.into()), Token::Symbol(s) => Expr::Symbol(s.into()),
Token::Keyword(k) => Expr::Keyword(k.into()), Token::Keyword(k) => Expr::Keyword(k.into()),
Token::String(s) => Expr::String(s.into()), Token::String(s) => Expr::String(s.into()),