diff --git a/src/lexer.rs b/src/lexer.rs index c8da9df..b40e459 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -16,9 +16,18 @@ pub enum Token<'a> { #[token("]")] RightBracket, + #[token("{")] + LeftCurly, + + #[token["}"]] + RightCurly, + #[token("'")] Quote, + #[token(",")] + Comma, + // Values #[regex("\"(\\.|[^\"])*\"", (lex_slice::<1, 1>))] String(&'a str), diff --git a/src/parser.rs b/src/parser.rs index cdc4c99..6a25819 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -33,6 +33,15 @@ fn parser<'a>() -> impl Parser, Vec, Error = Simple>> .map(Value::Vector) .delimited_by(just(Token::LeftBracket), just(Token::RightBracket)); + let map = value + .clone() + .then(value.clone()) + .separated_by(just(Token::Comma)) + .allow_trailing() + .collect() + .map(Value::Map) + .delimited_by(just(Token::LeftCurly), just(Token::RightCurly)); + let quote = just(Token::Quote).ignore_then(value).map(|value| { Value::List(Box::new(List::Cons( Value::Symbol("quote".to_owned()), @@ -40,9 +49,10 @@ fn parser<'a>() -> impl Parser, Vec, Error = Simple>> ))) }); - atom.or(list).or(vector).or(quote) + atom.or(list).or(vector).or(map).or(quote) }) .repeated() + .then_ignore(end()) } /// Convert Logos' Lexer into Chumsky'a Stream diff --git a/src/value.rs b/src/value.rs index a3ae1bb..79f66f1 100644 --- a/src/value.rs +++ b/src/value.rs @@ -1,11 +1,13 @@ use crate::list::List; use ordered_float::OrderedFloat; +use std::collections::BTreeMap; /// A Wisp value #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub enum Value { List(Box), Vector(Vec), + Map(BTreeMap), Symbol(String), Keyword(String), Function { args: Vec, body: Box },