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)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum Ident {
|
pub enum Ident {
|
||||||
|
|
@ -21,8 +21,8 @@ pub enum Ast {
|
||||||
outputs: Vec<Symbol>,
|
outputs: Vec<Symbol>,
|
||||||
body: Vec<Ast>,
|
body: Vec<Ast>,
|
||||||
},
|
},
|
||||||
/// `{x, y: z}`
|
/// `{^x; ^y := z}`
|
||||||
Map(Map<Ast>),
|
Map(Vec<Ast>),
|
||||||
/// `f x`
|
/// `f x`
|
||||||
App(Box<Ast>, Box<Ast>),
|
App(Box<Ast>, Box<Ast>),
|
||||||
/// `x + y` (only builtins, sorry)
|
/// `x + y` (only builtins, sorry)
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,22 @@ where
|
||||||
.delimited_by(just(Token::OpenParen), just(Token::CloseParen))
|
.delimited_by(just(Token::OpenParen), just(Token::CloseParen))
|
||||||
.labelled("block");
|
.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
|
let app = non_app
|
||||||
.clone()
|
.clone()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue