Skip to content

Commit 4e019a5

Browse files
authored
fix: allow fully qualified type name from other packages (#83)
1 parent ef59501 commit 4e019a5

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

ecsact/detail/grammar.hh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,20 @@ struct whitespace {
6565
lexy::dsl::inline_<line_comment> | lexy::dsl::inline_<block_comment>;
6666
};
6767

68+
/**
69+
* Lookupable type name
70+
*/
6871
struct type_name {
72+
static constexpr auto rule = lexy::dsl::
73+
identifier(lexy::dsl::ascii::alpha, lexy::dsl::ascii::alnum / lexy::dsl::lit_c<'.'>);
74+
75+
static constexpr auto value = lexy::as_string<std::string_view>;
76+
};
77+
78+
/**
79+
* Type name used for declaration
80+
*/
81+
struct type_name_decl {
6982
static constexpr auto rule =
7083
lexy::dsl::identifier(lexy::dsl::ascii::alpha, lexy::dsl::ascii::alnum);
7184

@@ -179,7 +192,7 @@ struct component_statement {
179192
};
180193

181194
static constexpr auto rule = lexy::dsl::p<component_keyword> >>
182-
lexy::dsl::p<type_name>;
195+
lexy::dsl::p<type_name_decl>;
183196

184197
static constexpr auto value =
185198
lexy::callback<ecsact_statement>([](std::string_view component_name) {
@@ -206,7 +219,7 @@ struct transient_statement {
206219
};
207220

208221
static constexpr auto rule = lexy::dsl::p<transient_keyword> >>
209-
lexy::dsl::p<type_name>;
222+
lexy::dsl::p<type_name_decl>;
210223

211224
static constexpr auto value =
212225
lexy::callback<ecsact_statement>([](std::string_view transient_name) {
@@ -229,7 +242,7 @@ struct system_statement {
229242
};
230243

231244
static constexpr auto rule = lexy::dsl::p<system_keyword> >>
232-
lexy::dsl::opt(lexy::dsl::p<type_name>);
245+
lexy::dsl::opt(lexy::dsl::p<type_name_decl>);
233246

234247
static constexpr auto value = lexy::callback<ecsact_statement>(
235248
[](std::optional<std::string_view> system_name) {
@@ -257,7 +270,7 @@ struct action_statement {
257270
};
258271

259272
static constexpr auto rule = lexy::dsl::p<action_keyword> >>
260-
lexy::dsl::p<type_name>;
273+
lexy::dsl::p<type_name_decl>;
261274

262275
static constexpr auto value =
263276
lexy::callback<ecsact_statement>([](std::string_view action_name) {
@@ -284,7 +297,7 @@ struct enum_statement {
284297
};
285298

286299
static constexpr auto rule = lexy::dsl::p<enum_keyword> >>
287-
lexy::dsl::p<type_name>;
300+
lexy::dsl::p<type_name_decl>;
288301

289302
static constexpr auto value =
290303
lexy::callback<ecsact_statement>([](std::string_view enum_name) {

test/parse_test_system_component_statement.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,24 @@ TEST(Parse, IncludeSystemComponentWithEntity) {
204204
"example_entity"
205205
);
206206
}
207+
208+
////////////////////////////////////
209+
// components from other packages //
210+
////////////////////////////////////
211+
212+
TEST(Parse, OtherPackageFullyQualified) {
213+
TestValidSystemComponent(
214+
"readwrite other.pkg.ExampleComponent;"s,
215+
ECSACT_SYS_CAP_READWRITE,
216+
"other.pkg.ExampleComponent"
217+
);
218+
}
219+
220+
TEST(Parse, IncludeSystemComponentWithEntityFullQualified) {
221+
TestValidSystemComponent(
222+
"include other.pkg.ExampleComponent with example_entity;"s,
223+
ECSACT_SYS_CAP_INCLUDE,
224+
"other.pkg.ExampleComponent",
225+
"example_entity"
226+
);
227+
}

0 commit comments

Comments
 (0)