parse maps
This commit is contained in:
parent
255c9f2109
commit
86fb16faea
2 changed files with 19 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{map::Map, symbol::Symbol, val::Val};
|
||||
use crate::{symbol::Symbol, val::Val};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum Ident {
|
||||
|
|
@ -21,8 +21,8 @@ pub enum Ast {
|
|||
outputs: Vec<Symbol>,
|
||||
body: Vec<Ast>,
|
||||
},
|
||||
/// `{x, y: z}`
|
||||
Map(Map<Ast>),
|
||||
/// `{^x; ^y := z}`
|
||||
Map(Vec<Ast>),
|
||||
/// `f x`
|
||||
App(Box<Ast>, Box<Ast>),
|
||||
/// `x + y` (only builtins, sorry)
|
||||
|
|
|
|||
|
|
@ -133,7 +133,22 @@ where
|
|||
.delimited_by(just(Token::OpenParen), just(Token::CloseParen))
|
||||
.labelled("block");
|
||||
|
||||
let non_app = choice((set, num, ident.map(Ast::Var).labelled("variable"), block));
|
||||
let map = expr
|
||||
.clone()
|
||||
.separated_by(semicolon.clone())
|
||||
.allow_trailing()
|
||||
.collect()
|
||||
.map(Ast::Map)
|
||||
.delimited_by(just(Token::OpenBrace), just(Token::CloseBrace))
|
||||
.labelled("map");
|
||||
|
||||
let non_app = choice((
|
||||
set,
|
||||
num,
|
||||
ident.map(Ast::Var).labelled("variable"),
|
||||
map,
|
||||
block,
|
||||
));
|
||||
|
||||
let app = non_app
|
||||
.clone()
|
||||
|
|
|
|||
Loading…
Reference in a new issue