Skip to content

Commit

Permalink
fix: allow nesting for return run function
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Dec 17, 2023
1 parent 6a16ad5 commit 21f542c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions examples/basic_nesting/src/data/demo/functions/foo.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,13 @@ function demo:blob:
append function demo:blob:
say aaaaa
say after

function demo:ret1:
execute if score some score matches 0 run return run execute run function demo:ret1/cond:
say hi
return 0

function demo:ret2:
execute if score some score matches 0 run return run function demo:ret2/cond:
say hi
return 0
3 changes: 2 additions & 1 deletion mecha/contrib/nesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def nesting_execute_run(self, node: AstCommand):
return node

@rule(AstCommand, identifier="execute:run:subcommand")
def nesting_execute_function(self, node: AstCommand):
@rule(AstCommand, identifier="return:run:subcommand")
def nesting_run_function(self, node: AstCommand):
if isinstance(command := node.arguments[0], AstCommand):
if command.identifier in self.identifier_map:
yield from self.handle_function(command)
Expand Down
26 changes: 26 additions & 0 deletions tests/snapshots/examples__build_basic_nesting__0.pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@ say anonymous definition 7
say anonymous definition 8
```

`@function demo:ret1/cond`

```mcfunction
say hi
return 0
```

`@function demo:ret2/cond`

```mcfunction
say hi
return 0
```

`@function demo:thing1`

```mcfunction
Expand Down Expand Up @@ -290,6 +304,18 @@ say aaaaa
say after
```

`@function demo:ret1`

```mcfunction
execute if score some score matches 0 run return run function demo:ret1/cond
```

`@function demo:ret2`

```mcfunction
execute if score some score matches 0 run return run function demo:ret2/cond
```

`@function demo:wat/nested_execute_0`

```mcfunction
Expand Down

0 comments on commit 21f542c

Please sign in to comment.