diff --git a/examples/clue_solver.ds b/examples/clue_solver.ds index 30c30d7..961db40 100644 --- a/examples/clue_solver.ds +++ b/examples/clue_solver.ds @@ -3,20 +3,26 @@ suspects = ['White' 'Green'] weapons = ['Rope' 'Lead_Pipe'] cards = [rooms suspects weapons] -take_turn = function current_room opponent_card - remove_card opponent_card - make_guess current_room +take_turn = |current_room opponent_card| => { + (remove_card opponent_card) + (make_guess current_room) +} -remove_card = function opponent_card - for card_list in cards +remove_card = |opponent_card| => { + for card_list in cards { removed = remove card from card_list card == opponent_card + } - if type removed == 'empty' + if (type removed) == 'empty' output 'Card not found.' +} -make_guess = function current_room - if length suspects == 1 && length rooms == 1 && length weapons == 1 +make_guess = |current_room| => { + if ((length suspects) == 1) + && ((length rooms) == 1) + && ((length weapons) == 1) + { (output 'It was ' + suspects:0 + ' in the ' @@ -24,7 +30,7 @@ make_guess = function current_room + ' with the ' + weapons:0 + '!') - else + } else { (output 'I accuse ' + (random suspects) + ' in the ' @@ -32,5 +38,7 @@ make_guess = function current_room + ' with the ' + (random weapons) + '!') + } +} (make_guess 'Library') diff --git a/examples/fibonacci.ds b/examples/fibonacci.ds index 5da7b17..ad5b0b5 100644 --- a/examples/fibonacci.ds +++ b/examples/fibonacci.ds @@ -1,4 +1,4 @@ -fib = function { +fib = |i| => { if i <= 1 { 1 } else { diff --git a/examples/table.ds b/examples/table.ds index 10bf4b7..1c2157b 100644 --- a/examples/table.ds +++ b/examples/table.ds @@ -1,31 +1,31 @@ -my_table = table [ +my_table = table |text number bool| [ ["a", 1, true] ["b", 2, true] ["a", 3, true] ] -test_table = table [ +test_table = table |text bool| [ ["a", true] ["b", true] ["a", true] ] -test_select = select from my_table +test_select = select |text bool| from my_table (assert_equal test_select, test_table) -test_table = table [ +test_table = table |text number bool| [ [1, true] [3, true] ] -test_select_where = select from my_table { +test_select_where = select |number, bool| from my_table { text == "a" } (assert_equal test_select_where, test_table) -test_table = table [ +test_table = table |text number bool| [ ["a", 1, true] ["b", 2, true] ["a", 3, true] diff --git a/src/abstract_tree/built_in_function.rs b/src/abstract_tree/built_in_function.rs index b311b9e..35c7ed9 100644 --- a/src/abstract_tree/built_in_function.rs +++ b/src/abstract_tree/built_in_function.rs @@ -94,13 +94,13 @@ impl AbstractTree for BuiltInFunction { BuiltInFunction::AssertEqual(expressions) } "download" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::Download(expression) } "help" => { - let child_node = node.child(2).unwrap(); + let child_node = node.child(1).unwrap(); let expression = if child_node.is_named() { Some(Expression::from_syntax_node(source, child_node)?) } else { @@ -110,7 +110,7 @@ impl AbstractTree for BuiltInFunction { BuiltInFunction::Help(expression) } "length" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::Length(expression) @@ -126,7 +126,7 @@ impl AbstractTree for BuiltInFunction { BuiltInFunction::OutputError(expressions) } "type" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::Type(expression) @@ -140,7 +140,7 @@ impl AbstractTree for BuiltInFunction { BuiltInFunction::Append(expressions) } "metadata" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::Metadata(expression) @@ -153,13 +153,13 @@ impl AbstractTree for BuiltInFunction { BuiltInFunction::Move(expressions) } "read" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::Read(expression) } "remove" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::Remove(expression) @@ -172,25 +172,25 @@ impl AbstractTree for BuiltInFunction { BuiltInFunction::Write(expressions) } "from_json" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::FromJson(expression) } "to_json" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::ToJson(expression) } "to_string" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::ToString(expression) } "to_float" => { - let expression_node = node.child(2).unwrap(); + let expression_node = node.child(1).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; BuiltInFunction::ToFloat(expression) diff --git a/src/abstract_tree/find.rs b/src/abstract_tree/find.rs index d6cb9f8..165cd65 100644 --- a/src/abstract_tree/find.rs +++ b/src/abstract_tree/find.rs @@ -18,7 +18,7 @@ impl AbstractTree for Find { let expression_node = node.child(3).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; - let item_node = node.child(5).unwrap(); + let item_node = node.child(4).unwrap(); let item = Block::from_syntax_node(source, item_node)?; Ok(Find { diff --git a/src/abstract_tree/for.rs b/src/abstract_tree/for.rs index 3ddc41b..72206c6 100644 --- a/src/abstract_tree/for.rs +++ b/src/abstract_tree/for.rs @@ -33,7 +33,7 @@ impl AbstractTree for For { let expression_node = node.child(3).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; - let item_node = node.child(5).unwrap(); + let item_node = node.child(4).unwrap(); let item = Block::from_syntax_node(source, item_node)?; Ok(For { diff --git a/src/abstract_tree/remove.rs b/src/abstract_tree/remove.rs index 6992527..29aace0 100644 --- a/src/abstract_tree/remove.rs +++ b/src/abstract_tree/remove.rs @@ -18,7 +18,7 @@ impl AbstractTree for Remove { let expression_node = node.child(3).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; - let item_node = node.child(5).unwrap(); + let item_node = node.child(4).unwrap(); let item = Block::from_syntax_node(source, item_node)?; Ok(Remove { diff --git a/src/abstract_tree/transform.rs b/src/abstract_tree/transform.rs index 9bf3776..1c0b8f0 100644 --- a/src/abstract_tree/transform.rs +++ b/src/abstract_tree/transform.rs @@ -19,7 +19,7 @@ impl AbstractTree for Transform { let expression_node = node.child(3).unwrap(); let expression = Expression::from_syntax_node(source, expression_node)?; - let item_node = node.child(5).unwrap(); + let item_node = node.child(4).unwrap(); let item = Block::from_syntax_node(source, item_node)?; Ok(Transform {