Skip to content

Commit

Permalink
feat: add n selector variable
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Jul 21, 2024
1 parent 3b34357 commit 40e9991
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mecha/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ class AstSelectorArgument(AstNode):
class AstSelector(AstNode):
"""Ast selector node."""

variable: Literal["p", "r", "a", "e", "s"] = required_field()
variable: Literal["p", "r", "a", "e", "s", "n"] = required_field()
arguments: AstChildren[AstSelectorArgument] = AstChildren()

parser = "selector"
Expand Down
4 changes: 2 additions & 2 deletions mecha/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ class SelectorParser:

def __call__(self, stream: TokenStream) -> AstSelector:
with stream.syntax(
selector=r"@[praes]\[?",
selector=r"@[praesn]\[?",
bracket=r"\[|\]",
comma=r",",
):
Expand Down Expand Up @@ -1881,7 +1881,7 @@ def __call__(self, stream: TokenStream) -> Any:
if not isinstance(node, AstSelector):
return node

is_single = node.variable in "prs"
is_single = node.variable in "prsn"

for arg in node.arguments:
if arg.key.value == "limit":
Expand Down
1 change: 1 addition & 0 deletions tests/resources/command_examples.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,4 @@ execute if predicate {condition: weather_check,raining: true}
particle minecraft:block{block_state: {Name: "minecraft:redstone_lamp",Properties: {lit: "true"}}}
execute store result storage test:test path double 0.0000000000009094947017729282 run say hello
give @p diamond_axe[!tool]
kill @n[type=pig]
30 changes: 28 additions & 2 deletions tests/snapshots/parse__command_examples__0.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<class 'mecha.ast.AstRoot'>
location: SourceLocation(pos=0, lineno=1, colno=1)
end_location: SourceLocation(pos=9903, lineno=234, colno=1)
end_location: SourceLocation(pos=9921, lineno=235, colno=1)
commands:
<class 'mecha.ast.AstCommand'>
location: SourceLocation(pos=14, lineno=2, colno=1)
Expand Down Expand Up @@ -8520,4 +8520,30 @@
is_tag: False
namespace: None
path: 'tool'
data_tags: None
data_tags: None
<class 'mecha.ast.AstCommand'>
location: SourceLocation(pos=9903, lineno=234, colno=1)
end_location: SourceLocation(pos=9920, lineno=234, colno=18)
identifier: 'kill:targets'
arguments:
<class 'mecha.ast.AstSelector'>
location: SourceLocation(pos=9908, lineno=234, colno=6)
end_location: SourceLocation(pos=9920, lineno=234, colno=18)
variable: 'n'
arguments:
<class 'mecha.ast.AstSelectorArgument'>
location: SourceLocation(pos=9911, lineno=234, colno=9)
end_location: SourceLocation(pos=9919, lineno=234, colno=17)
inverted: False
key:
<class 'mecha.ast.AstString'>
location: SourceLocation(pos=9911, lineno=234, colno=9)
end_location: SourceLocation(pos=9915, lineno=234, colno=13)
value: 'type'
value:
<class 'mecha.ast.AstResourceLocation'>
location: SourceLocation(pos=9916, lineno=234, colno=14)
end_location: SourceLocation(pos=9919, lineno=234, colno=17)
is_tag: False
namespace: None
path: 'pig'
1 change: 1 addition & 0 deletions tests/snapshots/parse__command_examples__1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,4 @@ execute if predicate {condition: "weather_check", raining: 1b}
particle minecraft:block{block_state: {Name: "minecraft:redstone_lamp", Properties: {lit: "true"}}}
execute store result storage test:test path double 0.0000000000009094947017729282 run say hello
give @p diamond_axe[!tool]
kill @n[type=pig]

0 comments on commit 40e9991

Please sign in to comment.