diff --git a/mecha/ast.py b/mecha/ast.py index f3b0ec9a..0343702b 100644 --- a/mecha/ast.py +++ b/mecha/ast.py @@ -832,6 +832,7 @@ class AstNbtByteArray(AstNbt): elements: AstChildren[AstNbt] = required_field() parser = None + array_prefix = "B" def evaluate(self) -> Any: return ByteArray([element.evaluate() for element in self.elements]) # type: ignore @@ -844,6 +845,7 @@ class AstNbtIntArray(AstNbt): elements: AstChildren[AstNbt] = required_field() parser = None + array_prefix = "I" def evaluate(self) -> Any: return IntArray([element.evaluate() for element in self.elements]) # type: ignore @@ -856,6 +858,7 @@ class AstNbtLongArray(AstNbt): elements: AstChildren[AstNbt] = required_field() parser = None + array_prefix = "L" def evaluate(self) -> Any: return LongArray([element.evaluate() for element in self.elements]) # type: ignore diff --git a/mecha/parse.py b/mecha/parse.py index dbd5a4da..adc89469 100644 --- a/mecha/parse.py +++ b/mecha/parse.py @@ -184,7 +184,7 @@ from .config import CommandTree from .error import MechaError from .spec import CommandSpec, Parser -from .utils import JsonQuoteHelper, QuoteHelper, string_to_number +from .utils import JsonQuoteHelper, NbtQuoteHelper, QuoteHelper, string_to_number NUMBER_PATTERN: str = r"-?(?:\d+\.?\d*|\.\d+)" @@ -493,8 +493,8 @@ def get_default_parsers() -> Dict[str, Parser]: ] ), "command:argument:minecraft:column_pos": delegate("column_pos"), - "command:argument:minecraft:component": MultilineParser(delegate("json")), - "command:argument:minecraft:style": MultilineParser(delegate("json")), + "command:argument:minecraft:component": MultilineParser(delegate("nbt")), + "command:argument:minecraft:style": MultilineParser(delegate("nbt")), "command:argument:minecraft:dimension": delegate("resource_location"), "command:argument:minecraft:entity": delegate("entity"), "command:argument:minecraft:entity_anchor": delegate("entity_anchor"), @@ -583,6 +583,12 @@ def get_parsers(version: VersionNumber = LATEST_MINECRAFT_VERSION) -> Dict[str, if version < (1, 20): parsers["scoreboard_slot"] = BasicLiteralParser(AstLegacyScoreboardSlot) + if version < (1, 21): + parsers["command:argument:minecraft:component"] = MultilineParser( + delegate("json") + ) + parsers["command:argument:minecraft:style"] = MultilineParser(delegate("json")) + return parsers @@ -1165,13 +1171,7 @@ class NbtParser: } ) - quote_helper: QuoteHelper = field( - default_factory=lambda: QuoteHelper( - escape_sequences={ - r"\\": "\\", - } - ) - ) + quote_helper: QuoteHelper = field(default_factory=NbtQuoteHelper) def __post_init__(self): self.compound_entry_parser = self.parse_compound_entry @@ -1234,24 +1234,16 @@ def __call__(self, stream: TokenStream) -> AstNbt: node = AstNbtLongArray(elements=AstChildren(elements)) element_type = Long # type: ignore msg = "Expected all elements to be long integers." + + node = set_location(node, array, stream.current) + + for element in node.elements: + if isinstance(element, AstNbtValue): + if type(element.value) is not element_type: + raise element.emit_error(InvalidSyntax(msg)) else: node = AstNbtList(elements=AstChildren(elements)) - element_type = None - msg = "Expected all elements to have the same type." - - node = set_location(node, bracket or array, stream.current) - - for element in node.elements: - if isinstance(element, AstNbtValue): - if not element_type: - element_type = type(element.value) - elif type(element.value) is not element_type: - raise element.emit_error(InvalidSyntax(msg)) - elif isinstance(element, AstNbt): # type: ignore - if not element_type: - element_type = type(element) - elif type(element) is not element_type: - raise element.emit_error(InvalidSyntax(msg)) + node = set_location(node, bracket, stream.current) return node diff --git a/mecha/serialize.py b/mecha/serialize.py index 2193befd..2650fff0 100644 --- a/mecha/serialize.py +++ b/mecha/serialize.py @@ -32,12 +32,17 @@ AstMacroLineText, AstMacroLineVariable, AstMessage, - AstNbt, AstNbtBool, + AstNbtByteArray, AstNbtCompound, + AstNbtCompoundKey, + AstNbtIntArray, + AstNbtList, + AstNbtLongArray, AstNbtPath, AstNbtPathKey, AstNbtPathSubscript, + AstNbtValue, AstNode, AstNumber, AstParticle, @@ -61,9 +66,10 @@ from .database import CompilationDatabase from .dispatch import Visitor, rule from .spec import CommandSpec -from .utils import QuoteHelper, number_to_string +from .utils import NbtQuoteHelper, QuoteHelper, number_to_string REGEX_COMMENTS = re.compile(r"^(?:(\s*#.*)|.+)", re.MULTILINE) +UNQUOTED_COMPOUND_KEY = re.compile(r"^[a-zA-Z0-9._+-]+$") class FormattingOptions(BaseModel): @@ -97,6 +103,7 @@ class Serializer(Visitor): } ) ) + nbt_quote_helper: QuoteHelper = field(default_factory=NbtQuoteHelper) def __call__(self, node: AstNode, **kwargs: Any) -> str: # type: ignore result: List[str] = [] @@ -237,14 +244,68 @@ def json(self, node: AstJson, result: List[str]): ) ) - @rule(AstNbt) - def nbt(self, node: AstNbt, result: List[str]): - result.append(node.evaluate().snbt(compact=self.formatting.nbt_compact)) + @rule(AstNbtValue) + def nbt_value(self, node: AstNbtValue, result: List[str]): + if isinstance(node.value, str): + result.append(self.nbt_quote_helper.quote_string(node.value)) + else: + result.append(node.evaluate().snbt(compact=self.formatting.nbt_compact)) @rule(AstNbtBool) def nbt_bool(self, node: AstNbtBool, result: List[str]): result.append("true" if node.value else "false") + @rule(AstNbtList) + def nbt_list(self, node: AstNbtList, result: List[str]): + result.append("[") + comma = "," if self.formatting.nbt_compact else ", " + sep = "" + for element in node.elements: + result.append(sep) + sep = comma + yield element + result.append("]") + + @rule(AstNbtCompoundKey) + def nbt_compound_key(self, node: AstNbtCompoundKey, result: List[str]): + if UNQUOTED_COMPOUND_KEY.match(node.value): + result.append(node.value) + else: + result.append(self.nbt_quote_helper.quote_string(node.value)) + + @rule(AstNbtCompound) + def nbt_compound(self, node: AstNbtCompound, result: List[str]): + result.append("{") + comma, colon = (",", ":") if self.formatting.nbt_compact else (", ", ": ") + sep = "" + for entry in node.entries: + result.append(sep) + sep = comma + yield entry.key + result.append(colon) + yield entry.value + result.append("}") + + @rule(AstNbtByteArray) + @rule(AstNbtIntArray) + @rule(AstNbtLongArray) + def nbt_array( + self, + node: Union[AstNbtByteArray, AstNbtIntArray, AstNbtLongArray], + result: List[str], + ): + result.append("[") + result.append(node.array_prefix) + semicolon = ";" if self.formatting.nbt_compact else "; " + result.append(semicolon) + comma = "," if self.formatting.nbt_compact else ", " + sep = "" + for element in node.elements: + result.append(sep) + sep = comma + yield element + result.append("]") + @rule(AstResourceLocation) def resource_location(self, node: AstResourceLocation, result: List[str]): result.append(node.get_value()) diff --git a/mecha/utils.py b/mecha/utils.py index d34f0ee5..8eec31b6 100644 --- a/mecha/utils.py +++ b/mecha/utils.py @@ -2,6 +2,7 @@ "QuoteHelper", "QuoteHelperWithUnicode", "JsonQuoteHelper", + "NbtQuoteHelper", "InvalidEscapeSequence", "normalize_whitespace", "string_to_number", @@ -14,7 +15,7 @@ import re from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, List, Optional, Union from beet import File from beet.core.utils import FileSystemPath @@ -25,6 +26,7 @@ ESCAPE_REGEX = re.compile(r"\\.") UNICODE_ESCAPE_REGEX = re.compile(r"\\(?:u([0-9a-fA-F]{4})|.)") AVOID_QUOTES_REGEX = re.compile(r"^[0-9A-Za-z_\.\+\-]+$") +QUOTE_REGEX = re.compile(r"\"|'") WHITESPACE_REGEX = re.compile(r"\s+") @@ -70,10 +72,15 @@ class QuoteHelper: avoid_quotes_regex: "re.Pattern[str]" = AVOID_QUOTES_REGEX escape_sequences: Dict[str, str] = field(default_factory=dict) + unquote_only_escape_characters: List[str] = field(default_factory=list) escape_characters: Dict[str, str] = field(init=False) def __post_init__(self): - self.escape_characters = {v: k for k, v in self.escape_sequences.items()} + self.escape_characters = { + v: k + for k, v in self.escape_sequences.items() + if not k in self.unquote_only_escape_characters + } def unquote_string(self, token: Token) -> str: """Remove quotes and substitute escaped characters.""" @@ -106,9 +113,14 @@ def quote_string(self, value: str, quote: str = '"') -> str: """Wrap the string in quotes if it can't be represented unquoted.""" if self.avoid_quotes_regex.match(value): return value + value = self.handle_quoting(value) + return quote + value.replace(quote, "\\" + quote) + quote + + def handle_quoting(self, value: str) -> str: + """Handle escape characters during quoting.""" for match, seq in self.escape_characters.items(): value = value.replace(match, seq) - return quote + value.replace(quote, "\\" + quote) + quote + return value @dataclass @@ -122,6 +134,17 @@ def handle_substitution(self, token: Token, match: "re.Match[str]") -> str: return chr(int(unicode_hex, 16)) return super().handle_substitution(token, match) + def handle_quoting(self, value: str) -> str: + value = super().handle_quoting(value) + + def escape_char(char: str) -> str: + codepoint = ord(char) + if codepoint < 128: + return char + return f"\\u{codepoint:04x}" + + return "".join(escape_char(c) for c in value) + @dataclass class JsonQuoteHelper(QuoteHelperWithUnicode): @@ -138,6 +161,31 @@ class JsonQuoteHelper(QuoteHelperWithUnicode): ) +@dataclass +class NbtQuoteHelper(QuoteHelperWithUnicode): + """Quote helper used for snbt.""" + + escape_sequences: Dict[str, str] = field( + default_factory=lambda: { + r"\\": "\\", + r"\b": "\b", + r"\f": "\f", + r"\n": "\n", + r"\r": "\r", + r"\s": " ", + r"\t": "\t", + } + ) + unquote_only_escape_characters: List[str] = field(default_factory=lambda: [r"\s"]) + + def quote_string(self, value: str, quote: Optional[str] = None) -> str: + if not quote: + found = QUOTE_REGEX.search(value) + quote = "'" if found and found.group() == '"' else '"' + value = super().handle_quoting(value) + return quote + value.replace(quote, "\\" + quote) + quote + + def underline_code( source: str, location: SourceLocation, diff --git a/tests/resources/argument_examples.json b/tests/resources/argument_examples.json index dcee5106..b08d9a6a 100644 --- a/tests/resources/argument_examples.json +++ b/tests/resources/argument_examples.json @@ -145,12 +145,13 @@ "{\"text\":\"hello world\"}", "[\"\"]", "\"\\u2588\"", - "{\"\\u2588\\\"\\n\":[123]}" + "{\"\\u2588\\\"\\n\":[123]}", + "wat" ] }, { "invalid": true, - "examples": ["wat", "{\"hey\": ]}"] + "examples": ["{\"hey\": ]}"] } ], "minecraft:dimension": [ @@ -415,18 +416,18 @@ "[L;1l,2l]", "[a, b, c]", "[[], [1], [foo]]", - "[[],[[[[[[[[[[],[[[[5,1]],[]]]]]]]]]]],[[[[]]]]]]" + "[[],[[[[[[[[[[],[[[[5,1]],[]]]]]]]]]]],[[[[]]]]]]", + "\"\\n\"", + "[a,1]", + "[[],[],1b]" ] }, { "invalid": true, "examples": [ "\"\\\"", - "\"\\n\"", "\"\\\\\\\"", "{\"\\\":1}", - "[a,1]", - "[[],[],1b]", "[B;5l,4l,3]", "[I;5l,4l,3]", "[L;5l,4l,3]", diff --git a/tests/snapshots/examples__build_basic_formatting__0.pack.md b/tests/snapshots/examples__build_basic_formatting__0.pack.md index 3c02b5b1..596dd120 100644 --- a/tests/snapshots/examples__build_basic_formatting__0.pack.md +++ b/tests/snapshots/examples__build_basic_formatting__0.pack.md @@ -20,7 +20,7 @@ ```mcfunction say this is a test execute as @a[nbt={SelectedItem:{id:"minecraft:diamond",Count:64b}}] at @s run setblock ~ ~ ~ repeater[delay=3,facing=south] -tellraw @a ["",{"text":"hello","color":"red"},"not ascii: \u00b6"] +tellraw @a ["",{text:"hello",color:"red"},"not ascii: \u00b6"] say goodbye ``` @@ -29,7 +29,7 @@ say goodbye ```mcfunction say this is a test execute as @a[nbt={SelectedItem: {id: "minecraft:diamond", Count: 64b}}] at @s run setblock ~ ~ ~ repeater[delay=3, facing=south] -tellraw @a ["", {"text": "hello", "color": "red"}, "not ascii: \u00b6"] +tellraw @a ["", {text: "hello", color: "red"}, "not ascii: \u00b6"] say goodbye ``` @@ -44,7 +44,7 @@ execute as @a[nbt={SelectedItem: {id: "minecraft:diamond", Count: 64b}}] at @s r -tellraw @a ["", {"text": "hello", "color": "red"}, "not ascii: \u00b6"] +tellraw @a ["", {text: "hello", color: "red"}, "not ascii: \u00b6"] @@ -63,7 +63,7 @@ execute as @a[nbt={SelectedItem:{id:"minecraft:diamond",Count:64b}}] at @s run s -tellraw @a ["", {"color": "red", "text": "hello"}, "not ascii: ΒΆ"] +tellraw @a ["",{text:"hello",color:"red"},"not ascii: \u00b6"] diff --git a/tests/snapshots/examples__build_basic_json__0.pack.md b/tests/snapshots/examples__build_basic_json__0.pack.md index af4e9040..9ae931ff 100644 --- a/tests/snapshots/examples__build_basic_json__0.pack.md +++ b/tests/snapshots/examples__build_basic_json__0.pack.md @@ -18,7 +18,7 @@ `@function demo:foo` ```mcfunction -tellraw @p {"text": "empty"} +tellraw @p {text: "empty"} ``` `@loot_table demo:foo` diff --git a/tests/snapshots/examples__build_basic_nested_yaml__0.pack.md b/tests/snapshots/examples__build_basic_nested_yaml__0.pack.md index 51eeada2..967249d2 100644 --- a/tests/snapshots/examples__build_basic_nested_yaml__0.pack.md +++ b/tests/snapshots/examples__build_basic_nested_yaml__0.pack.md @@ -18,12 +18,12 @@ `@function demo:foo` ```mcfunction -tellraw @a ["", {"text": "hello", "color": "red"}] -tellraw @a ["", {"text": "hello", "color": "red"}] +tellraw @a ["", {text: "hello", color: "red"}] +tellraw @a ["", {text: "hello", color: "red"}] summon armor_stand ~ ~ ~ {Tags: ["position_history", "new"], Invisible: 1b, Marker: 1b} summon armor_stand ~ ~ ~ {Tags: ["position_history", "new"], Invisible: 1b, Marker: 1b} -tellraw @s {"text": "Hover me!", "hoverEvent": {"action": "show_text", "value": "Hi!"}} -tellraw @a {"text": "Hello # there"} -tellraw @a {"text": "Hello\" # \"there"} -data merge storage demo:foo {custom_stuff: {list_of_lists: [[0, 0, 0], [1, 1, 1]], normal_lists: [[0, 0, 0], [1, 1, 1]]}, something_else: [{type: "foo", foo: 42}, {type: "bar", bar: 99}], byte_array: [B; 1B, 1B, 0B, 1B], item1: {id: "player_head", count: 1b, components: {"minecraft:profile": "herobrine"}}, item2: {id: "player_head", count: 1b, components: {"minecraft:profile": "herobrine"}}} +tellraw @s {text: "Hover me!", hoverEvent: {action: "show_text", value: "Hi!"}} +tellraw @a {text: "Hello # there"} +tellraw @a {text: 'Hello" # "there'} +data merge storage demo:foo {custom_stuff: {list_of_lists: [[0, 0, 0], [1, 1, 1]], normal_lists: [[0, 0, 0], [1, 1, 1]]}, something_else: [{type: "foo", foo: 42}, {type: "bar", bar: 99}], byte_array: [B; 1b, 1b, 0b, 1b], item1: {id: "player_head", count: 1b, components: {"minecraft:profile": "herobrine"}}, item2: {id: "player_head", count: 1b, components: {"minecraft:profile": "herobrine"}}} ``` diff --git a/tests/snapshots/examples__build_basic_preserve__0.pack.md b/tests/snapshots/examples__build_basic_preserve__0.pack.md index 32947763..c1a5a94f 100644 --- a/tests/snapshots/examples__build_basic_preserve__0.pack.md +++ b/tests/snapshots/examples__build_basic_preserve__0.pack.md @@ -50,7 +50,7 @@ execute as @a at @s align xyz if block ~ ~ ~ wool[foo=bar] run summon armor_stan # consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse # cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat # non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. -tellraw @s {"text": "Hover me!", "hoverEvent": {"action": "show_text", "value": "Hi!"}} +tellraw @s {text: "Hover me!", hoverEvent: {action: "show_text", value: "Hi!"}} # The hover event is cool @@ -84,7 +84,7 @@ execute as @a at @s if block ~ ~-1 ~ #wool run give @s stone{display: {Name: '[{ execute if block ~ ~ ~ #namespace:tag if entity @s[tag=foo] -tellraw @a {"text": "Hello # there"} +tellraw @a {text: "Hello # there"} diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_0_0__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_0_0__0.txt index 18d743b1..6ad18c74 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_component_0_0__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_component_0_0__0.txt @@ -6,7 +6,7 @@ minecraft:component 0 0 --- "hello world" --- - + location: SourceLocation(pos=0, lineno=1, colno=1) end_location: SourceLocation(pos=13, lineno=1, colno=14) - value: 'hello world' \ No newline at end of file + value: String('hello world') \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_0_1__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_0_1__0.txt index c1119025..6719c1a4 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_component_0_1__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_component_0_1__0.txt @@ -6,7 +6,7 @@ minecraft:component 0 1 --- "" --- - + location: SourceLocation(pos=0, lineno=1, colno=1) end_location: SourceLocation(pos=2, lineno=1, colno=3) - value: '' \ No newline at end of file + value: String('') \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_0_2__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_0_2__0.txt index 5b7661c0..6c9d09ad 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_component_0_2__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_component_0_2__0.txt @@ -4,22 +4,22 @@ minecraft:component 0 2 --- {"text":"hello world"} --- -{"text": "hello world"} +{text: "hello world"} --- - + location: SourceLocation(pos=0, lineno=1, colno=1) end_location: SourceLocation(pos=22, lineno=1, colno=23) entries: - + location: SourceLocation(pos=1, lineno=1, colno=2) end_location: SourceLocation(pos=21, lineno=1, colno=22) key: - + location: SourceLocation(pos=1, lineno=1, colno=2) end_location: SourceLocation(pos=7, lineno=1, colno=8) value: 'text' value: - + location: SourceLocation(pos=8, lineno=1, colno=9) end_location: SourceLocation(pos=21, lineno=1, colno=22) - value: 'hello world' \ No newline at end of file + value: String('hello world') \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_0_3__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_0_3__0.txt index 3e493e25..a628e552 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_component_0_3__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_component_0_3__0.txt @@ -6,11 +6,11 @@ minecraft:component 0 3 --- [""] --- - + location: SourceLocation(pos=0, lineno=1, colno=1) end_location: SourceLocation(pos=4, lineno=1, colno=5) elements: - + location: SourceLocation(pos=1, lineno=1, colno=2) end_location: SourceLocation(pos=3, lineno=1, colno=4) - value: '' \ No newline at end of file + value: String('') \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_0_4__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_0_4__0.txt index 164bd7ce..3480f77a 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_component_0_4__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_component_0_4__0.txt @@ -6,7 +6,7 @@ minecraft:component 0 4 --- "\u2588" --- - + location: SourceLocation(pos=0, lineno=1, colno=1) end_location: SourceLocation(pos=8, lineno=1, colno=9) - value: 'β–ˆ' \ No newline at end of file + value: String('β–ˆ') \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_0_5__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_0_5__0.txt index 25965c7b..0fe42726 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_component_0_5__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_component_0_5__0.txt @@ -4,26 +4,26 @@ minecraft:component 0 5 --- {"\u2588\"\n":[123]} --- -{"\u2588\"\n": [123]} +{'\u2588"\n': [123]} --- - + location: SourceLocation(pos=0, lineno=1, colno=1) end_location: SourceLocation(pos=20, lineno=1, colno=21) entries: - + location: SourceLocation(pos=1, lineno=1, colno=2) end_location: SourceLocation(pos=19, lineno=1, colno=20) key: - + location: SourceLocation(pos=1, lineno=1, colno=2) end_location: SourceLocation(pos=13, lineno=1, colno=14) value: 'β–ˆ"\n' value: - + location: SourceLocation(pos=14, lineno=1, colno=15) end_location: SourceLocation(pos=19, lineno=1, colno=20) elements: - + location: SourceLocation(pos=15, lineno=1, colno=16) end_location: SourceLocation(pos=18, lineno=1, colno=19) - value: 123 \ No newline at end of file + value: Int(123) \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_0_6__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_0_6__0.txt new file mode 100644 index 00000000..0a322da4 --- /dev/null +++ b/tests/snapshots/parse__argument_examples_minecraft_component_0_6__0.txt @@ -0,0 +1,12 @@ +minecraft:component 0 6 +--- +{} +--- +wat +--- +"wat" +--- + + location: SourceLocation(pos=0, lineno=1, colno=1) + end_location: SourceLocation(pos=3, lineno=1, colno=4) + value: String('wat') \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_1_0__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_1_0__0.txt index 63b5ebf3..e4c083ef 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_component_1_0__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_component_1_0__0.txt @@ -2,8 +2,8 @@ minecraft:component 1 0 --- {} --- -wat +{"hey": ]} --- Reported 1 error. -line 1, column 1: Expected bracket '[', curly '{', false, null, number, string or true but got literal 'wat'. \ No newline at end of file +line 1, column 9: Expected array, bracket '[', curly '{', number, quoted_string or string but got bracket ']'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_component_1_1__0.txt b/tests/snapshots/parse__argument_examples_minecraft_component_1_1__0.txt deleted file mode 100644 index 147029b8..00000000 --- a/tests/snapshots/parse__argument_examples_minecraft_component_1_1__0.txt +++ /dev/null @@ -1,9 +0,0 @@ -minecraft:component 1 1 ---- -{} ---- -{"hey": ]} ---- -Reported 1 error. - -line 1, column 9: Expected bracket '[', curly '{', false, null, number, string or true but got bracket ']'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_loot_predicate_0_1__0.txt b/tests/snapshots/parse__argument_examples_minecraft_loot_predicate_0_1__0.txt index 34bb6115..ffb828f9 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_loot_predicate_0_1__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_loot_predicate_0_1__0.txt @@ -4,7 +4,7 @@ minecraft:loot_predicate 0 1 --- {condition:weather_check, raining:true} --- -{condition: "weather_check", raining: 1b} +{condition: "weather_check", raining: true} --- location: SourceLocation(pos=0, lineno=1, colno=1) diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_12__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_12__0.txt new file mode 100644 index 00000000..b9457b97 --- /dev/null +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_12__0.txt @@ -0,0 +1,12 @@ +minecraft:nbt_tag 0 12 +--- +{} +--- +"\n" +--- +"\n" +--- + + location: SourceLocation(pos=0, lineno=1, colno=1) + end_location: SourceLocation(pos=4, lineno=1, colno=5) + value: String('\n') \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_13__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_13__0.txt new file mode 100644 index 00000000..82f70f9f --- /dev/null +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_13__0.txt @@ -0,0 +1,20 @@ +minecraft:nbt_tag 0 13 +--- +{} +--- +[a,1] +--- +["a", 1] +--- + + location: SourceLocation(pos=0, lineno=1, colno=1) + end_location: SourceLocation(pos=5, lineno=1, colno=6) + elements: + + location: SourceLocation(pos=1, lineno=1, colno=2) + end_location: SourceLocation(pos=2, lineno=1, colno=3) + value: String('a') + + location: SourceLocation(pos=3, lineno=1, colno=4) + end_location: SourceLocation(pos=4, lineno=1, colno=5) + value: Int(1) \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_14__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_14__0.txt new file mode 100644 index 00000000..8d6192ce --- /dev/null +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_14__0.txt @@ -0,0 +1,26 @@ +minecraft:nbt_tag 0 14 +--- +{} +--- +[[],[],1b] +--- +[[], [], 1b] +--- + + location: SourceLocation(pos=0, lineno=1, colno=1) + end_location: SourceLocation(pos=10, lineno=1, colno=11) + elements: + + location: SourceLocation(pos=1, lineno=1, colno=2) + end_location: SourceLocation(pos=3, lineno=1, colno=4) + elements: + + + location: SourceLocation(pos=4, lineno=1, colno=5) + end_location: SourceLocation(pos=6, lineno=1, colno=7) + elements: + + + location: SourceLocation(pos=7, lineno=1, colno=8) + end_location: SourceLocation(pos=9, lineno=1, colno=10) + value: Byte(1) \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_6__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_6__0.txt index 046942f6..20f89a9f 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_6__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_0_6__0.txt @@ -4,7 +4,7 @@ minecraft:nbt_tag 0 6 --- [B; 1b] --- -[B; 1B] +[B; 1b] --- location: SourceLocation(pos=0, lineno=1, colno=1) diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_10__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_10__0.txt index a59bd6de..4fce7770 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_10__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_10__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 10 --- {} --- -{with space: 5} +{error: [test]]} --- Reported 1 error. -line 1, column 7: Expected colon but got string 'space'. \ No newline at end of file +line 1, column 15: Expected curly '}' but got bracket ']'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_11__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_11__0.txt index c145633b..cb44390f 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_11__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_11__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 11 --- {} --- -{\": no} +[{,{}] --- Reported 1 error. -line 1, column 2: Expected number, quoted_string or string but got literal '\\"'. \ No newline at end of file +line 1, column 3: Expected number, quoted_string or string but got comma ','. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_12__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_12__0.txt index c6b81fb8..5be3efd5 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_12__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_12__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 12 --- {} --- -{foo: [1,2} +"\'" --- Reported 1 error. -line 1, column 11: Expected bracket ']' but got curly '}'. \ No newline at end of file +line 1, column 2: Invalid escape sequence \'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_13__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_13__0.txt index cf86a0a9..48e7b64a 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_13__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_13__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 13 --- {} --- -{error: [test]]} +'\"' --- Reported 1 error. -line 1, column 15: Expected curly '}' but got bracket ']'. \ No newline at end of file +line 1, column 2: Invalid escape sequence \". \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_14__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_14__0.txt deleted file mode 100644 index f6c9a897..00000000 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_14__0.txt +++ /dev/null @@ -1,9 +0,0 @@ -minecraft:nbt_tag 1 14 ---- -{} ---- -[{,{}] ---- -Reported 1 error. - -line 1, column 3: Expected number, quoted_string or string but got comma ','. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_15__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_15__0.txt deleted file mode 100644 index 7e398688..00000000 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_15__0.txt +++ /dev/null @@ -1,9 +0,0 @@ -minecraft:nbt_tag 1 15 ---- -{} ---- -"\'" ---- -Reported 1 error. - -line 1, column 2: Invalid escape sequence \'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_16__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_16__0.txt deleted file mode 100644 index 3af0ec9e..00000000 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_16__0.txt +++ /dev/null @@ -1,9 +0,0 @@ -minecraft:nbt_tag 1 16 ---- -{} ---- -'\"' ---- -Reported 1 error. - -line 1, column 2: Invalid escape sequence \". \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_1__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_1__0.txt index dbea3a58..011f0641 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_1__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_1__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 1 --- {} --- -"\n" +"\\\" --- Reported 1 error. -line 1, column 2: Invalid escape sequence \n. \ No newline at end of file +line 1, column 1: Expected array, bracket '[', curly '{', number, quoted_string or string but got literal '"\\\\\\"'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_2__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_2__0.txt index abceb8d9..d4d405a1 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_2__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_2__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 2 --- {} --- -"\\\" +{"\":1} --- Reported 1 error. -line 1, column 1: Expected array, bracket '[', curly '{', number, quoted_string or string but got literal '"\\\\\\"'. \ No newline at end of file +line 1, column 2: Expected number, quoted_string or string but got literal '"\\"'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_3__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_3__0.txt index 633b491a..6d2bb3f3 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_3__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_3__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 3 --- {} --- -{"\":1} +[B;5l,4l,3] --- Reported 1 error. -line 1, column 2: Expected number, quoted_string or string but got literal '"\\"'. \ No newline at end of file +line 1, column 4: Expected all elements to be bytes. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_4__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_4__0.txt index 40f01676..d5fc810a 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_4__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_4__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 4 --- {} --- -[a,1] +[I;5l,4l,3] --- Reported 1 error. -line 1, column 4: Expected all elements to have the same type. \ No newline at end of file +line 1, column 4: Expected all elements to be integers. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_5__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_5__0.txt index 3b58a582..065b8847 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_5__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_5__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 5 --- {} --- -[[],[],1b] +[L;5l,4l,3] --- Reported 1 error. -line 1, column 8: Expected all elements to have the same type. \ No newline at end of file +line 1, column 10: Expected all elements to be long integers. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_6__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_6__0.txt index 524136c5..0c7fc1dc 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_6__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_6__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 6 --- {} --- -[B;5l,4l,3] +{hello,world} --- Reported 1 error. -line 1, column 4: Expected all elements to be bytes. \ No newline at end of file +line 1, column 7: Expected colon but got comma ','. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_7__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_7__0.txt index d38c65d0..32ed598c 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_7__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_7__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 7 --- {} --- -[I;5l,4l,3] +{with space: 5} --- Reported 1 error. -line 1, column 4: Expected all elements to be integers. \ No newline at end of file +line 1, column 7: Expected colon but got string 'space'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_8__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_8__0.txt index e0061e9c..19f7d318 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_8__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_8__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 8 --- {} --- -[L;5l,4l,3] +{\": no} --- Reported 1 error. -line 1, column 10: Expected all elements to be long integers. \ No newline at end of file +line 1, column 2: Expected number, quoted_string or string but got literal '\\"'. \ No newline at end of file diff --git a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_9__0.txt b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_9__0.txt index c534dc72..56401961 100644 --- a/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_9__0.txt +++ b/tests/snapshots/parse__argument_examples_minecraft_nbt_tag_1_9__0.txt @@ -2,8 +2,8 @@ minecraft:nbt_tag 1 9 --- {} --- -{hello,world} +{foo: [1,2} --- Reported 1 error. -line 1, column 7: Expected colon but got comma ','. \ No newline at end of file +line 1, column 11: Expected bracket ']' but got curly '}'. \ No newline at end of file diff --git a/tests/snapshots/parse__command_examples__0.txt b/tests/snapshots/parse__command_examples__0.txt index 3e4548e8..95414e89 100644 --- a/tests/snapshots/parse__command_examples__0.txt +++ b/tests/snapshots/parse__command_examples__0.txt @@ -5061,10 +5061,10 @@ variable: 'a' arguments: - + location: SourceLocation(pos=5551, lineno=133, colno=12) end_location: SourceLocation(pos=5568, lineno=133, colno=29) - value: 'text to display' + value: String('text to display') location: SourceLocation(pos=5569, lineno=134, colno=1) end_location: SourceLocation(pos=5615, lineno=134, colno=47) @@ -5076,36 +5076,36 @@ variable: 'a' arguments: - + location: SourceLocation(pos=5580, lineno=134, colno=12) end_location: SourceLocation(pos=5615, lineno=134, colno=47) entries: - + location: SourceLocation(pos=5581, lineno=134, colno=13) end_location: SourceLocation(pos=5599, lineno=134, colno=31) key: - + location: SourceLocation(pos=5581, lineno=134, colno=13) end_location: SourceLocation(pos=5587, lineno=134, colno=19) value: 'text' value: - + location: SourceLocation(pos=5588, lineno=134, colno=20) end_location: SourceLocation(pos=5599, lineno=134, colno=31) - value: 'I am blue' - + value: String('I am blue') + location: SourceLocation(pos=5600, lineno=134, colno=32) end_location: SourceLocation(pos=5614, lineno=134, colno=46) key: - + location: SourceLocation(pos=5600, lineno=134, colno=32) end_location: SourceLocation(pos=5607, lineno=134, colno=39) value: 'color' value: - + location: SourceLocation(pos=5608, lineno=134, colno=40) end_location: SourceLocation(pos=5614, lineno=134, colno=46) - value: 'blue' + value: String('blue') location: SourceLocation(pos=5616, lineno=135, colno=1) end_location: SourceLocation(pos=5665, lineno=135, colno=50) @@ -5117,36 +5117,36 @@ variable: 'a' arguments: - + location: SourceLocation(pos=5627, lineno=135, colno=12) end_location: SourceLocation(pos=5665, lineno=135, colno=50) entries: - + location: SourceLocation(pos=5628, lineno=135, colno=13) end_location: SourceLocation(pos=5646, lineno=135, colno=31) key: - + location: SourceLocation(pos=5628, lineno=135, colno=13) end_location: SourceLocation(pos=5634, lineno=135, colno=19) value: 'text' value: - + location: SourceLocation(pos=5635, lineno=135, colno=20) end_location: SourceLocation(pos=5646, lineno=135, colno=31) - value: 'I am blue' - + value: String('I am blue') + location: SourceLocation(pos=5647, lineno=135, colno=32) end_location: SourceLocation(pos=5664, lineno=135, colno=49) key: - + location: SourceLocation(pos=5647, lineno=135, colno=32) end_location: SourceLocation(pos=5654, lineno=135, colno=39) value: 'color' value: - + location: SourceLocation(pos=5655, lineno=135, colno=40) end_location: SourceLocation(pos=5664, lineno=135, colno=49) - value: '#5555ff' + value: String('#5555ff') location: SourceLocation(pos=5666, lineno=136, colno=1) end_location: SourceLocation(pos=5747, lineno=136, colno=82) @@ -5158,62 +5158,62 @@ variable: 'a' arguments: - + location: SourceLocation(pos=5677, lineno=136, colno=12) end_location: SourceLocation(pos=5747, lineno=136, colno=82) entries: - + location: SourceLocation(pos=5678, lineno=136, colno=13) end_location: SourceLocation(pos=5696, lineno=136, colno=31) key: - + location: SourceLocation(pos=5678, lineno=136, colno=13) end_location: SourceLocation(pos=5684, lineno=136, colno=19) value: 'text' value: - + location: SourceLocation(pos=5685, lineno=136, colno=20) end_location: SourceLocation(pos=5696, lineno=136, colno=31) - value: 'Hover me!' - + value: String('Hover me!') + location: SourceLocation(pos=5697, lineno=136, colno=32) end_location: SourceLocation(pos=5746, lineno=136, colno=81) key: - + location: SourceLocation(pos=5697, lineno=136, colno=32) end_location: SourceLocation(pos=5709, lineno=136, colno=44) value: 'hoverEvent' value: - + location: SourceLocation(pos=5710, lineno=136, colno=45) end_location: SourceLocation(pos=5746, lineno=136, colno=81) entries: - + location: SourceLocation(pos=5711, lineno=136, colno=46) end_location: SourceLocation(pos=5731, lineno=136, colno=66) key: - + location: SourceLocation(pos=5711, lineno=136, colno=46) end_location: SourceLocation(pos=5719, lineno=136, colno=54) value: 'action' value: - + location: SourceLocation(pos=5720, lineno=136, colno=55) end_location: SourceLocation(pos=5731, lineno=136, colno=66) - value: 'show_text' - + value: String('show_text') + location: SourceLocation(pos=5732, lineno=136, colno=67) end_location: SourceLocation(pos=5745, lineno=136, colno=80) key: - + location: SourceLocation(pos=5732, lineno=136, colno=67) end_location: SourceLocation(pos=5739, lineno=136, colno=74) value: 'value' value: - + location: SourceLocation(pos=5740, lineno=136, colno=75) end_location: SourceLocation(pos=5745, lineno=136, colno=80) - value: 'Hi!' + value: String('Hi!') location: SourceLocation(pos=5748, lineno=137, colno=1) end_location: SourceLocation(pos=5773, lineno=137, colno=26) @@ -5225,10 +5225,10 @@ variable: 'a' arguments: - + location: SourceLocation(pos=5759, lineno=137, colno=12) end_location: SourceLocation(pos=5773, lineno=137, colno=26) - value: 'Text1\nText2' + value: String('Text1\nText2') location: SourceLocation(pos=5781, lineno=139, colno=1) end_location: SourceLocation(pos=5795, lineno=139, colno=15) @@ -5266,49 +5266,49 @@ variable: 'a' arguments: - + location: SourceLocation(pos=5851, lineno=143, colno=19) end_location: SourceLocation(pos=5910, lineno=143, colno=78) entries: - + location: SourceLocation(pos=5852, lineno=143, colno=20) end_location: SourceLocation(pos=5880, lineno=143, colno=48) key: - + location: SourceLocation(pos=5852, lineno=143, colno=20) end_location: SourceLocation(pos=5858, lineno=143, colno=26) value: 'text' value: - + location: SourceLocation(pos=5859, lineno=143, colno=27) end_location: SourceLocation(pos=5880, lineno=143, colno=48) - value: 'The story begins...' - + value: String('The story begins...') + location: SourceLocation(pos=5881, lineno=143, colno=49) end_location: SourceLocation(pos=5895, lineno=143, colno=63) key: - + location: SourceLocation(pos=5881, lineno=143, colno=49) end_location: SourceLocation(pos=5888, lineno=143, colno=56) value: 'color' value: - + location: SourceLocation(pos=5889, lineno=143, colno=57) end_location: SourceLocation(pos=5895, lineno=143, colno=63) - value: 'gray' - + value: String('gray') + location: SourceLocation(pos=5896, lineno=143, colno=64) end_location: SourceLocation(pos=5909, lineno=143, colno=77) key: - + location: SourceLocation(pos=5896, lineno=143, colno=64) end_location: SourceLocation(pos=5904, lineno=143, colno=72) value: 'italic' value: - + location: SourceLocation(pos=5905, lineno=143, colno=73) end_location: SourceLocation(pos=5909, lineno=143, colno=77) - value: True + value: Byte(1) location: SourceLocation(pos=5911, lineno=144, colno=1) end_location: SourceLocation(pos=5958, lineno=144, colno=48) @@ -5320,36 +5320,36 @@ variable: 'a' arguments: - + location: SourceLocation(pos=5926, lineno=144, colno=16) end_location: SourceLocation(pos=5958, lineno=144, colno=48) entries: - + location: SourceLocation(pos=5927, lineno=144, colno=17) end_location: SourceLocation(pos=5945, lineno=144, colno=35) key: - + location: SourceLocation(pos=5927, lineno=144, colno=17) end_location: SourceLocation(pos=5933, lineno=144, colno=23) value: 'text' value: - + location: SourceLocation(pos=5934, lineno=144, colno=24) end_location: SourceLocation(pos=5945, lineno=144, colno=35) - value: 'Chapter I' - + value: String('Chapter I') + location: SourceLocation(pos=5946, lineno=144, colno=36) end_location: SourceLocation(pos=5957, lineno=144, colno=47) key: - + location: SourceLocation(pos=5946, lineno=144, colno=36) end_location: SourceLocation(pos=5952, lineno=144, colno=42) value: 'bold' value: - + location: SourceLocation(pos=5953, lineno=144, colno=43) end_location: SourceLocation(pos=5957, lineno=144, colno=47) - value: True + value: Byte(1) location: SourceLocation(pos=5969, lineno=146, colno=1) end_location: SourceLocation(pos=5987, lineno=146, colno=19) @@ -7273,23 +7273,23 @@ location: SourceLocation(pos=8564, lineno=211, colno=30) end_location: SourceLocation(pos=8567, lineno=211, colno=33) value: 'foo' - + location: SourceLocation(pos=8588, lineno=211, colno=54) end_location: SourceLocation(pos=8602, lineno=211, colno=68) entries: - + location: SourceLocation(pos=8589, lineno=211, colno=55) end_location: SourceLocation(pos=8601, lineno=211, colno=67) key: - + location: SourceLocation(pos=8589, lineno=211, colno=55) end_location: SourceLocation(pos=8595, lineno=211, colno=61) value: 'bold' value: - + location: SourceLocation(pos=8597, lineno=211, colno=63) end_location: SourceLocation(pos=8601, lineno=211, colno=67) - value: True + value: Byte(1) location: SourceLocation(pos=8603, lineno=212, colno=1) end_location: SourceLocation(pos=8636, lineno=212, colno=34) diff --git a/tests/snapshots/parse__command_examples__1.txt b/tests/snapshots/parse__command_examples__1.txt index 6643cace..1d5915f8 100644 --- a/tests/snapshots/parse__command_examples__1.txt +++ b/tests/snapshots/parse__command_examples__1.txt @@ -102,20 +102,20 @@ spreadplayers 0 0 200 500 true @a summon lightning_bolt ~-10 ~ ~ summon creeper ~ ~ ~ {powered: 1b, CustomName: '{"text":"Powered Creeper"}'} summon spider ~ ~ ~ {Passengers: [{id: "minecraft:skeleton", HandItems: [{id: "minecraft:bow", Count: 1b}]}]} -summon villager ~ ~ ~ {Offers: {Recipes: [{buy: {id: "dirt", Count: 1}, sell: {id: "diamond", Count: 1}, rewardExp: 0b}]}} +summon villager ~ ~ ~ {Offers: {Recipes: [{buy: {id: "dirt", Count: 1}, sell: {id: "diamond", Count: 1}, rewardExp: false}]}} teleport Alice teleport @a @s teleport 100 ~3 100 tellraw @a "text to display" -tellraw @a {"text": "I am blue", "color": "blue"} -tellraw @a {"text": "I am blue", "color": "#5555ff"} -tellraw @a {"text": "Hover me!", "hoverEvent": {"action": "show_text", "value": "Hi!"}} +tellraw @a {text: "I am blue", color: "blue"} +tellraw @a {text: "I am blue", color: "#5555ff"} +tellraw @a {text: "Hover me!", hoverEvent: {action: "show_text", value: "Hi!"}} tellraw @a "Text1\nText2" time set 1000 time set day time add 24000 -title @a subtitle {"text": "The story begins...", "color": "gray", "italic": true} -title @a title {"text": "Chapter I", "bold": true} +title @a subtitle {text: "The story begins...", color: "gray", italic: true} +title @a title {text: "Chapter I", bold: true} weather clear 1200 weather rain scoreboard players operation #sie_1_flags_delta integer = #sie_1_flags integer @@ -167,7 +167,7 @@ execute if function demo:foo run return run function demo:bar execute store result score @s foo run return run data get entity @s foodSaturationLevel gamerule maxCommandForkCount 9999 scoreboard objectives modify foo displayautoupdate true -scoreboard objectives modify foo numberformat styled {"bold": true} +scoreboard objectives modify foo numberformat styled {bold: true} give @s wooden_pickaxe[damage=23] give @s wooden_pickaxe[damage=23]{foo: 123} give @s netherite_hoe[damage=5, repair_cost=2] @@ -183,10 +183,10 @@ clear @s *[!damage | damage=0] clear @s *[count~{max: 2}] clear @s *[damage~{durability: {min: 3}}] clear @s *[custom_data~{gm4_metallurgy: {stored_shamir: "lumos"}}, damage | !max_item_stack=1] -execute if predicate {condition: "weather_check", raining: 1b} +execute if predicate {condition: "weather_check", raining: true} particle minecraft:block{block_state: {Name: "minecraft:redstone_lamp", Properties: {lit: "true"}}} clear @s *[custom_data~{gm4_metallurgy: {stored_shamir: "lumos"}}, damage | !max_item_stack=1] -execute if predicate {condition: "weather_check", raining: 1b} +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] diff --git a/tests/snapshots/parse__multiline_command_examples__0.txt b/tests/snapshots/parse__multiline_command_examples__0.txt index 53449bf5..f6acd504 100644 --- a/tests/snapshots/parse__multiline_command_examples__0.txt +++ b/tests/snapshots/parse__multiline_command_examples__0.txt @@ -408,62 +408,62 @@ variable: 's' arguments: - + location: SourceLocation(pos=542, lineno=29, colno=12) end_location: SourceLocation(pos=650, lineno=35, colno=2) entries: - + location: SourceLocation(pos=548, lineno=30, colno=5) end_location: SourceLocation(pos=567, lineno=30, colno=24) key: - + location: SourceLocation(pos=548, lineno=30, colno=5) end_location: SourceLocation(pos=554, lineno=30, colno=11) value: 'text' value: - + location: SourceLocation(pos=556, lineno=30, colno=13) end_location: SourceLocation(pos=567, lineno=30, colno=24) - value: 'Hover me!' - + value: String('Hover me!') + location: SourceLocation(pos=573, lineno=31, colno=5) end_location: SourceLocation(pos=648, lineno=34, colno=6) key: - + location: SourceLocation(pos=573, lineno=31, colno=5) end_location: SourceLocation(pos=585, lineno=31, colno=17) value: 'hoverEvent' value: - + location: SourceLocation(pos=587, lineno=31, colno=19) end_location: SourceLocation(pos=648, lineno=34, colno=6) entries: - + location: SourceLocation(pos=597, lineno=32, colno=9) end_location: SourceLocation(pos=618, lineno=32, colno=30) key: - + location: SourceLocation(pos=597, lineno=32, colno=9) end_location: SourceLocation(pos=605, lineno=32, colno=17) value: 'action' value: - + location: SourceLocation(pos=607, lineno=32, colno=19) end_location: SourceLocation(pos=618, lineno=32, colno=30) - value: 'show_text' - + value: String('show_text') + location: SourceLocation(pos=628, lineno=33, colno=9) end_location: SourceLocation(pos=642, lineno=33, colno=23) key: - + location: SourceLocation(pos=628, lineno=33, colno=9) end_location: SourceLocation(pos=635, lineno=33, colno=16) value: 'value' value: - + location: SourceLocation(pos=637, lineno=33, colno=18) end_location: SourceLocation(pos=642, lineno=33, colno=23) - value: 'Hi!' + value: String('Hi!') location: SourceLocation(pos=652, lineno=37, colno=1) end_location: SourceLocation(pos=975, lineno=51, colno=6) @@ -685,23 +685,23 @@ variable: 'a' arguments: - + location: SourceLocation(pos=1115, lineno=57, colno=12) end_location: SourceLocation(pos=1146, lineno=59, colno=2) entries: - + location: SourceLocation(pos=1121, lineno=58, colno=5) end_location: SourceLocation(pos=1144, lineno=58, colno=28) key: - + location: SourceLocation(pos=1121, lineno=58, colno=5) end_location: SourceLocation(pos=1127, lineno=58, colno=11) value: 'text' value: - + location: SourceLocation(pos=1129, lineno=58, colno=13) end_location: SourceLocation(pos=1144, lineno=58, colno=28) - value: 'Hello # there' + value: String('Hello # there') location: SourceLocation(pos=1148, lineno=61, colno=1) end_location: SourceLocation(pos=1214, lineno=64, colno=6) @@ -713,23 +713,23 @@ variable: 'a' arguments: - + location: SourceLocation(pos=1171, lineno=62, colno=5) end_location: SourceLocation(pos=1214, lineno=64, colno=6) entries: - + location: SourceLocation(pos=1181, lineno=63, colno=9) end_location: SourceLocation(pos=1208, lineno=63, colno=36) key: - + location: SourceLocation(pos=1181, lineno=63, colno=9) end_location: SourceLocation(pos=1187, lineno=63, colno=15) value: 'text' value: - + location: SourceLocation(pos=1189, lineno=63, colno=17) end_location: SourceLocation(pos=1208, lineno=63, colno=36) - value: 'Hello" # "there' + value: String('Hello" # "there') location: SourceLocation(pos=1216, lineno=66, colno=1) end_location: SourceLocation(pos=1234, lineno=66, colno=19) @@ -741,14 +741,14 @@ variable: 's' arguments: - + location: SourceLocation(pos=1227, lineno=66, colno=12) end_location: SourceLocation(pos=1234, lineno=66, colno=19) elements: - + location: SourceLocation(pos=1228, lineno=66, colno=13) end_location: SourceLocation(pos=1233, lineno=66, colno=18) - value: 'foo' + value: String('foo') location: SourceLocation(pos=1245, lineno=68, colno=1) end_location: SourceLocation(pos=1288, lineno=73, colno=9) diff --git a/tests/snapshots/parse__multiline_command_examples__1.txt b/tests/snapshots/parse__multiline_command_examples__1.txt index 129af165..3436a3fb 100644 --- a/tests/snapshots/parse__multiline_command_examples__1.txt +++ b/tests/snapshots/parse__multiline_command_examples__1.txt @@ -4,11 +4,11 @@ execute if block 0 0 0 #wool execute if block 0 0 0 wool execute if block 0 0 0 wool execute if block ~ 1 0 #wool -tellraw @s {"text": "Hover me!", "hoverEvent": {"action": "show_text", "value": "Hi!"}} +tellraw @s {text: "Hover me!", hoverEvent: {action: "show_text", value: "Hi!"}} execute as @a at @s if block ~ ~-1 ~ #wool run give @s stone{display: {Name: '[{"text": "Hello", "bold": true}]', Lore: ['[{ "text": "Something else here" }]']}} execute if block ~ ~ ~ #namespace:tag if entity @s[tag=foo] -tellraw @a {"text": "Hello # there"} -tellraw @a {"text": "Hello\" # \"there"} +tellraw @a {text: "Hello # there"} +tellraw @a {text: 'Hello" # "there'} tellraw @s ["foo"] say foo bar hello wat welp say this is a continuation @@ -29,5 +29,5 @@ execute if data storage demo:foo thing1.thing2{foo: 1, bar: [1, 2, 3]}.something data modify entity @s Attributes[{Name: "minecraft:generic.movement_speed"}].Modifiers append from storage demo:foo bar data modify entity @s Attributes[{Name: "minecraft:generic.movement_speed"}].Modifiers append from storage demo:foo bar clear @s *[custom_data~{gm4_metallurgy: {stored_shamir: "lumos"}}, damage | !max_item_stack=1] -execute if predicate {condition: "weather_check", raining: 1b} +execute if predicate {condition: "weather_check", raining: true} particle minecraft:block{block_state: {Name: "minecraft:redstone_lamp", Properties: {lit: "true"}}} diff --git a/tests/test_compile.py b/tests/test_compile.py index 18c0793f..194216f2 100644 --- a/tests/test_compile.py +++ b/tests/test_compile.py @@ -8,7 +8,7 @@ AstBool, AstChildren, AstCommand, - AstJsonValue, + AstNbtValue, AstMessage, AstMessageText, AstRoot, @@ -31,8 +31,8 @@ def convert_say_to_tellraw(node: AstCommand): arguments=AstChildren( [ AstSelector(variable="a"), - AstJsonValue( - value="".join( + AstNbtValue.from_value( + "".join( f.value for f in message.fragments if isinstance(f, AstMessageText)