mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Update lib.rs
This commit is contained in:
parent
7f28b2f8df
commit
0743717ce5
|
@ -6,12 +6,12 @@ pub type Spanned<T> = (T, std::ops::Range<usize>);
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
Int(i64), Float(f64), Boolean(bool),
|
Int(i64), Float(f64), Boolean(bool),
|
||||||
String(String), Identifier(String),
|
String(String), Identifier(String),
|
||||||
|
|
||||||
Unary { op: String, rhs: Box<Spanned<Self>> },
|
Unary { op: String, rhs: Box<Spanned<Self>> },
|
||||||
Binary { lhs: Box<Spanned<Self>>, op: String, rhs: Box<Spanned<Self>> },
|
Binary { lhs: Box<Spanned<Self>>, op: String, rhs: Box<Spanned<Self>> },
|
||||||
Call { name: Box<Spanned<Self>>, args: Spanned<Vec<Spanned<Self>>> },
|
Call { name: Box<Spanned<Self>>, args: Spanned<Vec<Spanned<Self>>> },
|
||||||
|
|
||||||
Let {
|
Let {
|
||||||
name: String,
|
name: String,
|
||||||
type_hint: String,
|
type_hint: String,
|
||||||
|
@ -24,7 +24,7 @@ pub enum Expr {
|
||||||
body: Box<Spanned<Self>>
|
body: Box<Spanned<Self>>
|
||||||
},
|
},
|
||||||
Return { expr: Box<Spanned<Self>> },
|
Return { expr: Box<Spanned<Self>> },
|
||||||
|
|
||||||
If {
|
If {
|
||||||
cond: Box<Spanned<Self>>,
|
cond: Box<Spanned<Self>>,
|
||||||
then: Box<Spanned<Self>>,
|
then: Box<Spanned<Self>>,
|
||||||
|
@ -69,13 +69,15 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
|
||||||
)
|
)
|
||||||
.repeated()
|
.repeated()
|
||||||
)
|
)
|
||||||
.foldl(|name, args| {(
|
.foldl(|name, args| {
|
||||||
|
(
|
||||||
Expr::Call {
|
Expr::Call {
|
||||||
name: Box::new(name.clone()),
|
name: Box::new(name.clone()),
|
||||||
args: (args, name.1.clone()),
|
args: (args, name.1.clone()),
|
||||||
},
|
},
|
||||||
name.1,
|
name.1,
|
||||||
)});
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let unary = choice((
|
let unary = choice((
|
||||||
just(Token::Plus),
|
just(Token::Plus),
|
||||||
|
|
Loading…
Reference in a new issue