[BREAKING CHANGE] change variable keyword to 'let' from 'var'

This commit is contained in:
Lukáš Hozda 2017-10-02 08:46:35 +02:00
parent 87b68b79f8
commit 660fbe2e39
7 changed files with 18 additions and 18 deletions

View File

@ -1,4 +1,4 @@
var x = [1, 2, 3]; let x = [1, 2, 3];
print(x[1]); print(x[1]);
x[1] = 5; x[1] = 5;
print(x[1]); print(x[1]);

View File

@ -1,2 +1,2 @@
var x = 78 let x = 78
print(x) print(x)

View File

@ -1,5 +1,5 @@
var a = true; let a = true;
if (a) { if (a) {
var x = 56; let x = 56;
print(x); print(x);
} }

View File

@ -1,4 +1,4 @@
var x = 1000000; let x = 1000000;
while x > 0 { while x > 0 {
x = x - 1; x = x - 1;
} }

View File

@ -1,4 +1,4 @@
var x = 10; let x = 10;
while x > 0 { while x > 0 {
print(x); print(x);

View File

@ -1438,7 +1438,7 @@ fn test_bool_op2() {
fn test_op_prec() { fn test_op_prec() {
let mut engine = Engine::new(); let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i64>("var x = 0; if x == 10 || true { x = 1} x") { if let Ok(result) = engine.eval::<i64>("let x = 0; if x == 10 || true { x = 1} x") {
assert_eq!(result, 1); assert_eq!(result, 1);
} else { } else {
assert!(false); assert!(false);
@ -1472,7 +1472,7 @@ fn test_if() {
fn test_while() { fn test_while() {
let mut engine = Engine::new(); let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i64>("var x = 0; while x < 10 { x = x + 1; if x > 5 { \ if let Ok(result) = engine.eval::<i64>("let x = 0; while x < 10 { x = x + 1; if x > 5 { \
break } } x") { break } } x") {
assert_eq!(result, 6); assert_eq!(result, 6);
} else { } else {
@ -1485,7 +1485,7 @@ fn test_var_scope() {
let mut engine = Engine::new(); let mut engine = Engine::new();
let mut scope: Scope = Vec::new(); let mut scope: Scope = Vec::new();
if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "var x = 4 + 5") { if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5") {
} else { } else {
assert!(false); assert!(false);
} }
@ -1507,7 +1507,7 @@ fn test_var_scope() {
assert!(false); assert!(false);
} }
if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "{var x = 3}") { if let Ok(_) = engine.eval_with_scope::<()>(&mut scope, "{let x = 3}") {
} else { } else {
assert!(false); assert!(false);
} }
@ -1543,7 +1543,7 @@ fn test_method_call() {
engine.register_fn("update", TestStruct::update); engine.register_fn("update", TestStruct::update);
engine.register_fn("new_ts", TestStruct::new); engine.register_fn("new_ts", TestStruct::new);
if let Ok(result) = engine.eval::<TestStruct>("var x = new_ts(); x.update(); x") { if let Ok(result) = engine.eval::<TestStruct>("let x = new_ts(); x.update(); x") {
assert_eq!(result.x, 1001); assert_eq!(result.x, 1001);
} else { } else {
assert!(false); assert!(false);
@ -1579,7 +1579,7 @@ fn test_get_set() {
engine.register_get_set("x", TestStruct::get_x, TestStruct::set_x); engine.register_get_set("x", TestStruct::get_x, TestStruct::set_x);
engine.register_fn("new_ts", TestStruct::new); engine.register_fn("new_ts", TestStruct::new);
if let Ok(result) = engine.eval::<i64>("var a = new_ts(); a.x = 500; a.x") { if let Ok(result) = engine.eval::<i64>("let a = new_ts(); a.x = 500; a.x") {
assert_eq!(result, 500); assert_eq!(result, 500);
} else { } else {
assert!(false); assert!(false);
@ -1636,7 +1636,7 @@ fn test_big_get_set() {
engine.register_fn("new_tp", TestParent::new); engine.register_fn("new_tp", TestParent::new);
if let Ok(result) = engine.eval::<i64>("var a = new_tp(); a.child.x = 500; a.child.x") { if let Ok(result) = engine.eval::<i64>("let a = new_tp(); a.child.x = 500; a.child.x") {
assert_eq!(result, 500); assert_eq!(result, 500);
} else { } else {
assert!(false); assert!(false);
@ -1693,13 +1693,13 @@ fn test_string() {
fn test_arrays() { fn test_arrays() {
let mut engine = Engine::new(); let mut engine = Engine::new();
if let Ok(result) = engine.eval::<i64>("var x = [1, 2, 3]; x[1]") { if let Ok(result) = engine.eval::<i64>("let x = [1, 2, 3]; x[1]") {
assert_eq!(result, 2); assert_eq!(result, 2);
} else { } else {
assert!(false); assert!(false);
} }
if let Ok(result) = engine.eval::<i64>("var y = [1, 2, 3]; y[1] = 5; y[1]") { if let Ok(result) = engine.eval::<i64>("let y = [1, 2, 3]; y[1] = 5; y[1]") {
assert_eq!(result, 5); assert_eq!(result, 5);
} else { } else {
assert!(false); assert!(false);
@ -1739,13 +1739,13 @@ fn test_array_with_structs() {
engine.register_fn("update", TestStruct::update); engine.register_fn("update", TestStruct::update);
engine.register_fn("new_ts", TestStruct::new); engine.register_fn("new_ts", TestStruct::new);
if let Ok(result) = engine.eval::<i64>("var a = [new_ts()]; a[0].x") { if let Ok(result) = engine.eval::<i64>("let a = [new_ts()]; a[0].x") {
assert_eq!(result, 1); assert_eq!(result, 1);
} else { } else {
assert!(false); assert!(false);
} }
if let Ok(result) = engine.eval::<i64>("var a = [new_ts()]; a[0].x = 100; a[0].update(); \ if let Ok(result) = engine.eval::<i64>("let a = [new_ts()]; a[0].x = 100; a[0].update(); \
a[0].x") { a[0].x") {
assert_eq!(result, 1100); assert_eq!(result, 1100);
} else { } else {

View File

@ -313,7 +313,7 @@ impl<'a> Iterator for TokenIterator<'a> {
return Some(Token::True); return Some(Token::True);
} else if out == "false" { } else if out == "false" {
return Some(Token::False); return Some(Token::False);
} else if out == "var" { } else if out == "let" {
return Some(Token::Var); return Some(Token::Var);
} else if out == "if" { } else if out == "if" {
return Some(Token::If); return Some(Token::If);