mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
don't treat js method as call
This commit is contained in:
parent
35ffd11321
commit
8b927e4ac7
|
@ -14,7 +14,7 @@ pub enum JSExpr {
|
||||||
Op(&'static str, Box<Self>, Option<Box<Self>>),
|
Op(&'static str, Box<Self>, Option<Box<Self>>),
|
||||||
|
|
||||||
Call(Box<Self>, Vec<Self>),
|
Call(Box<Self>, Vec<Self>),
|
||||||
Method(Box<Self>, String, Option<Vec<Self>>),
|
Method(Box<Self>, String),
|
||||||
Lambda {
|
Lambda {
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
body: Vec<Self>,
|
body: Vec<Self>,
|
||||||
|
@ -75,20 +75,7 @@ impl Display for JSExpr {
|
||||||
}
|
}
|
||||||
write!(f, ")")
|
write!(f, ")")
|
||||||
},
|
},
|
||||||
JSExpr::Method(c, m, args) => {
|
JSExpr::Method(c, m) => write!(f, "{}.{}", c, m),
|
||||||
write!(f, "{}.{}", c, m)?;
|
|
||||||
if let Some(args) = args {
|
|
||||||
write!(f, "(")?;
|
|
||||||
for (i, arg) in args.iter().enumerate() {
|
|
||||||
if i > 0 {
|
|
||||||
write!(f, ", ")?;
|
|
||||||
}
|
|
||||||
write!(f, "{}", arg)?;
|
|
||||||
}
|
|
||||||
write!(f, ")")?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
JSExpr::Lambda { args, body } => {
|
JSExpr::Lambda { args, body } => {
|
||||||
write!(f, "((")?;
|
write!(f, "((")?;
|
||||||
for (i, name) in args.iter().enumerate() {
|
for (i, name) in args.iter().enumerate() {
|
||||||
|
|
|
@ -154,24 +154,15 @@ pub fn translate_js_expr(expr: Expr) -> JSExpr {
|
||||||
match *f {
|
match *f {
|
||||||
Expr::Sym(ref s) => {
|
Expr::Sym(ref s) => {
|
||||||
match s.as_str() {
|
match s.as_str() {
|
||||||
"println" => {
|
"print" => JSExpr::Call(
|
||||||
JSExpr::Method(
|
|
||||||
Box::new(JSExpr::Sym("console".to_string())),
|
|
||||||
"log".to_string(),
|
|
||||||
Some(args.into_iter().map(translate_js_expr).collect()),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
"print" => {
|
|
||||||
JSExpr::Method(
|
|
||||||
Box::new(JSExpr::Method(
|
Box::new(JSExpr::Method(
|
||||||
Box::new(JSExpr::Sym("process".to_string())),
|
Box::new(JSExpr::Method(
|
||||||
"stdout".to_string(),
|
Box::new(JSExpr::Sym("process".to_string())),
|
||||||
None,
|
"stdout".to_string(),
|
||||||
|
)),
|
||||||
|
"write".to_string(),
|
||||||
)),
|
)),
|
||||||
"write".to_string(),
|
args.into_iter().map(translate_js_expr).collect()),
|
||||||
Some(args.into_iter().map(translate_js_expr).collect()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
_ => JSExpr::Call(
|
_ => JSExpr::Call(
|
||||||
Box::new(translate_js_expr(*f)),
|
Box::new(translate_js_expr(*f)),
|
||||||
args.into_iter().map(translate_js_expr).collect(),
|
args.into_iter().map(translate_js_expr).collect(),
|
||||||
|
|
Loading…
Reference in a new issue