Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion godot_parser/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def from_parser(cls: Type[GDObjectType], parse_result) -> GDObjectType:
return factory(*parse_result[1:])

def __str__(self) -> str:
return "%s( %s )" % (
return "%s(%s)" % (
self.name,
", ".join([stringify_object(v) for v in self.args]),
)
Expand Down
18 changes: 18 additions & 0 deletions godot_parser/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,30 @@
"GDExtResourceSection",
"GDSubResourceSection",
"GDResourceSection",
"GDTypedArray"
]


GD_SECTION_REGISTRY = {}


class GDTypedArray(object):
def __init__(self, inner_type, inner_value):
self.inner_type = inner_type
self.inner_value = inner_value

def __repr__(self) -> str:
return f"TypedArray({self.__str__()})"

def __str__(self) -> str:
return f"Array[{self.inner_type}]({self.inner_value})"

@classmethod
def from_parser(cls, parse_result):
inner_type, inner_value = parse_result
return cls(inner_type, inner_value)


class GDSectionHeader(object):
"""
Represents the header for a section
Expand Down
22 changes: 19 additions & 3 deletions godot_parser/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Forward,
Group,
Keyword,
Literal,
Opt,
Optional,
QuotedString,
Suppress,
Word,
Expand All @@ -15,6 +17,7 @@
)

from .objects import GDObject
from .sections import GDTypedArray

boolean = (
(Keyword("true") | Keyword("false"))
Expand All @@ -31,10 +34,11 @@
value = Forward()

# Vector2( 1, 2 )
# May not have args: PackedStringArray()
obj_type = (
Word(alphas, alphanums).set_results_name("object_name")
+ Suppress("(")
+ DelimitedList(value)
+ Opt(DelimitedList(value))
+ Suppress(")")
).set_parse_action(GDObject.from_parser)

Expand All @@ -44,7 +48,6 @@
Suppress("[") + Opt(DelimitedList(value)) + Opt(Suppress(",")) + Suppress("]")
)
.set_name("list")
.set_parse_action(lambda p: p.as_list())
)
key_val = Group(QuotedString('"', escChar="\\") + Suppress(":") + value)

Expand All @@ -57,6 +60,19 @@
.set_parse_action(lambda d: {k: v for k, v in d})
)

# Typed arrays: e.g. Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3, 4, 5)])
# Need to support, e.g.:
# polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(3, 2, 4, 5)])
typed_array = (
Literal("Array").suppress() +
Suppress("[") +
Word(alphanums + "_").set_results_name("inner_type") +
Suppress("]") +
Suppress("(") +
list_.set_results_name("inner_value") +
Suppress(")")
).set_name("typed_array").set_parse_action(GDTypedArray.from_parser)

# Exports

value <<= primitive | list_ | dict_ | obj_type
value <<= primitive | list_ | dict_ | obj_type | typed_array
Loading