Added map support
This commit is contained in:
parent
a5e5043c87
commit
8c47a30f8e
|
@ -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),
|
||||
|
|
|
@ -33,6 +33,15 @@ fn parser<'a>() -> impl Parser<Token<'a>, Vec<Value>, Error = Simple<Token<'a>>>
|
|||
.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<Token<'a>, Vec<Value>, Error = Simple<Token<'a>>>
|
|||
)))
|
||||
});
|
||||
|
||||
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
|
||||
|
|
|
@ -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<List>),
|
||||
Vector(Vec<Self>),
|
||||
Map(BTreeMap<Self, Self>),
|
||||
Symbol(String),
|
||||
Keyword(String),
|
||||
Function { args: Vec<Value>, body: Box<Value> },
|
||||
|
|
Loading…
Reference in a new issue