Repository: hedyorg/hedy

Issue:
Issue with addition in level 7
I am not sure what is the root cause here:

```
count is 1
repeat 12 times
    print count ' times 12 is ' count*12
    count is count + 1
```


Discussion:

Resolving patch:
diff --git a/hedy.py b/hedy.py
--- a/hedy.py
+++ b/hedy.py
@@ -175,7 +175,7 @@ def create_parser(level):
         grammar = file.read()
     return Lark(grammar)
 
-def all_arguments_true(args):
+def are_all_arguments_true(args):
     bool_arguments = [x[0] for x in args]
     arguments_of_false_nodes = [x[1] for x in args if not x[0]]
     return all(bool_arguments), arguments_of_false_nodes
@@ -195,64 +195,66 @@ def program(self, args):
                 command_num += 1
 
     def command(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     def assign(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def assign_list(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def assign_sum(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def list_access(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     # level 4 commands
     def list_access_var(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def ifs(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def valid_command(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def ifelse(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def condition(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def equality_check(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def in_list_check(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     # level 5 command
     def repeat(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     # level 6
     def addition(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def substraction(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def multiplication(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def division(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     #level 7
     def elses(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     # level 8
     def for_loop(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     # level 9
     def elifs(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     # level 12
     def change_list_item(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     #leafs are treated differently, they are True + their arguments flattened
+    def var(self, args):
+        return True, ''.join([str(c) for c in args])
     def random(self, args):
         return True, 'random'
     def index(self, args):
@@ -278,21 +280,19 @@ class IsValid(Filter):
     # that means you added a production rule but did not add a method for the rule here
 
     def ask(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def print(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def echo(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
     def for_loop(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
 
     #leafs with tokens need to be all true
     def var(self, args):
         return all(args), ''.join([c for c in args])
     def text(self, args):
         return all(args), ''.join([c for c in args])
-    def addition(self, args):
-        return all(args), ''.join([c for c in args])
 
     def invalid_space(self, args):
         # return space to indicate that line starts in a space
@@ -302,7 +302,9 @@ def print_nq(self, args):
         # return error source to indicate what went wrong
         return False, "print without quotes"
     def input(self, args):
-        return all_arguments_true(args)
+        return are_all_arguments_true(args)
+
+
 
 class IsComplete(Filter):
     # print, ask an echo can miss arguments and then are not complete
@@ -330,8 +332,6 @@ def var(self, args):
         return all(args), ''.join([c for c in args])
     def text(self, args):
         return all(args), ''.join([c for c in args])
-    def addition(self, args):
-        return all(args), ''.join([c for c in args])
     def input(self, args):
         return args != [], 'input'
 


Test patch:
diff --git a/tests/tests_level_07.py b/tests/tests_level_07.py
--- a/tests/tests_level_07.py
+++ b/tests/tests_level_07.py
@@ -218,6 +218,40 @@ def test_print_random(self):
     print('computer koos '+str(computerkeuze))""")
 
     self.assertEqual(expected, result)
+
+  def test_addition_simple(self):
+
+    code = textwrap.dedent("""\
+    var is 5
+    print var + 5""")
+
+    result = hedy.transpile(code, 7)
+
+    expected = textwrap.dedent("""\
+    var = '5'
+    print(str(int(var) + int(5)))""")
+
+    self.assertEqual(expected, result)
+
+  def test_issue_297(self):
+
+    code = textwrap.dedent("""\
+    count is 1
+    repeat 12 times
+      print count ' times 12 is ' count*12
+      count is count + 1""")
+
+    result = hedy.transpile(code, 7)
+
+    expected = textwrap.dedent("""\
+    count = '1'
+    for i in range(int(12)):
+      print(str(count)+' times 12 is '+str(int(count) * int(12)))
+      count = int(count) + int(1)""")
+
+    self.assertEqual(expected, result)
+
+
     
 #programs with issues to see if we catch them properly
 # (so this should fail, for now)