forked from AbleScript/ablescript
Improve consistency of code & comments
Changed all `&str.to_string()` into `&str.to_owned()`, and made the grammar of the `Value::into_*` comments uniform.
This commit is contained in:
parent
1b9f8a6179
commit
7673b64a71
|
@ -201,7 +201,7 @@ impl ExecEnv {
|
||||||
self.decl_var(
|
self.decl_var(
|
||||||
&iden.iden,
|
&iden.iden,
|
||||||
Value::Functio(Functio::AbleFunctio {
|
Value::Functio(Functio::AbleFunctio {
|
||||||
params: params.iter().map(|iden| iden.iden.to_string()).collect(),
|
params: params.iter().map(|iden| iden.iden.to_owned()).collect(),
|
||||||
body: body.block.to_owned(),
|
body: body.block.to_owned(),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
@ -558,7 +558,7 @@ mod tests {
|
||||||
rhs: Box::new(Expr {
|
rhs: Box::new(Expr {
|
||||||
kind: ExprKind::BinOp {
|
kind: ExprKind::BinOp {
|
||||||
lhs: Box::new(Expr {
|
lhs: Box::new(Expr {
|
||||||
kind: ExprKind::Variable("a".to_string()),
|
kind: ExprKind::Variable("a".to_owned()),
|
||||||
span: 5..6,
|
span: 5..6,
|
||||||
}),
|
}),
|
||||||
rhs: Box::new(Expr {
|
rhs: Box::new(Expr {
|
||||||
|
@ -594,7 +594,7 @@ mod tests {
|
||||||
let expected = &[Stmt {
|
let expected = &[Stmt {
|
||||||
kind: StmtKind::Var {
|
kind: StmtKind::Var {
|
||||||
iden: Iden {
|
iden: Iden {
|
||||||
iden: "a".to_string(),
|
iden: "a".to_owned(),
|
||||||
span: 4..5,
|
span: 4..5,
|
||||||
},
|
},
|
||||||
init: Some(Expr {
|
init: Some(Expr {
|
||||||
|
@ -631,7 +631,7 @@ mod tests {
|
||||||
body: Block {
|
body: Block {
|
||||||
block: vec![Stmt {
|
block: vec![Stmt {
|
||||||
kind: StmtKind::Print(Expr {
|
kind: StmtKind::Print(Expr {
|
||||||
kind: ExprKind::Literal(Value::Str("Buy Able products!".to_string())),
|
kind: ExprKind::Literal(Value::Str("Buy Able products!".to_owned())),
|
||||||
span: 19..39,
|
span: 19..39,
|
||||||
}),
|
}),
|
||||||
span: 19..46,
|
span: 19..46,
|
||||||
|
@ -651,17 +651,17 @@ mod tests {
|
||||||
let expected = &[Stmt {
|
let expected = &[Stmt {
|
||||||
kind: StmtKind::Var {
|
kind: StmtKind::Var {
|
||||||
iden: Iden {
|
iden: Iden {
|
||||||
iden: "script".to_string(),
|
iden: "script".to_owned(),
|
||||||
span: 13..17,
|
span: 13..17,
|
||||||
},
|
},
|
||||||
init: Some(Expr {
|
init: Some(Expr {
|
||||||
kind: ExprKind::BinOp {
|
kind: ExprKind::BinOp {
|
||||||
lhs: Box::new(Expr {
|
lhs: Box::new(Expr {
|
||||||
kind: ExprKind::Literal(Value::Str("script".to_string())),
|
kind: ExprKind::Literal(Value::Str("script".to_owned())),
|
||||||
span: 20..26,
|
span: 20..26,
|
||||||
}),
|
}),
|
||||||
rhs: Box::new(Expr {
|
rhs: Box::new(Expr {
|
||||||
kind: ExprKind::Variable("script".to_string()),
|
kind: ExprKind::Variable("script".to_owned()),
|
||||||
span: 29..33,
|
span: 29..33,
|
||||||
}),
|
}),
|
||||||
kind: BinOpKind::Add,
|
kind: BinOpKind::Add,
|
||||||
|
@ -684,7 +684,7 @@ mod tests {
|
||||||
kind: ExprKind::Cart(vec![
|
kind: ExprKind::Cart(vec![
|
||||||
(
|
(
|
||||||
Expr {
|
Expr {
|
||||||
kind: ExprKind::Literal(Value::Str("able".to_string())),
|
kind: ExprKind::Literal(Value::Str("able".to_owned())),
|
||||||
span: 1..7,
|
span: 1..7,
|
||||||
},
|
},
|
||||||
Expr {
|
Expr {
|
||||||
|
@ -694,7 +694,7 @@ mod tests {
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Expr {
|
Expr {
|
||||||
kind: ExprKind::Literal(Value::Str("script".to_string())),
|
kind: ExprKind::Literal(Value::Str("script".to_owned())),
|
||||||
span: 14..22,
|
span: 14..22,
|
||||||
},
|
},
|
||||||
Expr {
|
Expr {
|
||||||
|
@ -731,11 +731,11 @@ mod tests {
|
||||||
expr: Box::new(Expr {
|
expr: Box::new(Expr {
|
||||||
kind: ExprKind::Cart(vec![(
|
kind: ExprKind::Cart(vec![(
|
||||||
Expr {
|
Expr {
|
||||||
kind: ExprKind::Literal(Value::Str("able".to_string())),
|
kind: ExprKind::Literal(Value::Str("able".to_owned())),
|
||||||
span: 1..7,
|
span: 1..7,
|
||||||
},
|
},
|
||||||
Expr {
|
Expr {
|
||||||
kind: ExprKind::Literal(Value::Str("ablecorp".to_string())),
|
kind: ExprKind::Literal(Value::Str("ablecorp".to_owned())),
|
||||||
span: 11..21,
|
span: 11..21,
|
||||||
},
|
},
|
||||||
)]),
|
)]),
|
||||||
|
|
|
@ -113,7 +113,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Coerce a Value to a boolean. The conversion cannot fail.
|
/// Coerce a value to a boolean.
|
||||||
pub fn into_bool(self) -> bool {
|
pub fn into_bool(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Value::Abool(b) => b.into(),
|
Value::Abool(b) => b.into(),
|
||||||
|
@ -130,7 +130,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Coerce a Value to an aboolean
|
/// Coerce a value to an aboolean.
|
||||||
pub fn into_abool(self) -> Abool {
|
pub fn into_abool(self) -> Abool {
|
||||||
match self {
|
match self {
|
||||||
Value::Nul => Abool::Never,
|
Value::Nul => Abool::Never,
|
||||||
|
@ -170,7 +170,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Coerce a Value to a functio
|
/// Coerce a value to a functio.
|
||||||
pub fn into_functio(self) -> Functio {
|
pub fn into_functio(self) -> Functio {
|
||||||
match self {
|
match self {
|
||||||
Value::Nul => Functio::AbleFunctio {
|
Value::Nul => Functio::AbleFunctio {
|
||||||
|
@ -186,6 +186,7 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Coerce a value into a cart.
|
||||||
pub fn into_cart(self) -> Cart {
|
pub fn into_cart(self) -> Cart {
|
||||||
match self {
|
match self {
|
||||||
Value::Nul => HashMap::new(),
|
Value::Nul => HashMap::new(),
|
||||||
|
|
Loading…
Reference in a new issue