From 4e019a5697aa3992c3e9adcea5768f6df21d98a5 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Tue, 7 Mar 2023 14:51:04 -0800 Subject: [PATCH] fix: allow fully qualified type name from other packages (#83) --- ecsact/detail/grammar.hh | 23 +++++++++++++++---- test/parse_test_system_component_statement.cc | 21 +++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/ecsact/detail/grammar.hh b/ecsact/detail/grammar.hh index 352c523..1b3b5f7 100644 --- a/ecsact/detail/grammar.hh +++ b/ecsact/detail/grammar.hh @@ -65,7 +65,20 @@ struct whitespace { lexy::dsl::inline_ | lexy::dsl::inline_; }; +/** + * Lookupable type name + */ struct type_name { + static constexpr auto rule = lexy::dsl:: + identifier(lexy::dsl::ascii::alpha, lexy::dsl::ascii::alnum / lexy::dsl::lit_c<'.'>); + + static constexpr auto value = lexy::as_string; +}; + +/** + * Type name used for declaration + */ +struct type_name_decl { static constexpr auto rule = lexy::dsl::identifier(lexy::dsl::ascii::alpha, lexy::dsl::ascii::alnum); @@ -179,7 +192,7 @@ struct component_statement { }; static constexpr auto rule = lexy::dsl::p >> - lexy::dsl::p; + lexy::dsl::p; static constexpr auto value = lexy::callback([](std::string_view component_name) { @@ -206,7 +219,7 @@ struct transient_statement { }; static constexpr auto rule = lexy::dsl::p >> - lexy::dsl::p; + lexy::dsl::p; static constexpr auto value = lexy::callback([](std::string_view transient_name) { @@ -229,7 +242,7 @@ struct system_statement { }; static constexpr auto rule = lexy::dsl::p >> - lexy::dsl::opt(lexy::dsl::p); + lexy::dsl::opt(lexy::dsl::p); static constexpr auto value = lexy::callback( [](std::optional system_name) { @@ -257,7 +270,7 @@ struct action_statement { }; static constexpr auto rule = lexy::dsl::p >> - lexy::dsl::p; + lexy::dsl::p; static constexpr auto value = lexy::callback([](std::string_view action_name) { @@ -284,7 +297,7 @@ struct enum_statement { }; static constexpr auto rule = lexy::dsl::p >> - lexy::dsl::p; + lexy::dsl::p; static constexpr auto value = lexy::callback([](std::string_view enum_name) { diff --git a/test/parse_test_system_component_statement.cc b/test/parse_test_system_component_statement.cc index c7889a4..3cd3c96 100644 --- a/test/parse_test_system_component_statement.cc +++ b/test/parse_test_system_component_statement.cc @@ -204,3 +204,24 @@ TEST(Parse, IncludeSystemComponentWithEntity) { "example_entity" ); } + +//////////////////////////////////// +// components from other packages // +//////////////////////////////////// + +TEST(Parse, OtherPackageFullyQualified) { + TestValidSystemComponent( + "readwrite other.pkg.ExampleComponent;"s, + ECSACT_SYS_CAP_READWRITE, + "other.pkg.ExampleComponent" + ); +} + +TEST(Parse, IncludeSystemComponentWithEntityFullQualified) { + TestValidSystemComponent( + "include other.pkg.ExampleComponent with example_entity;"s, + ECSACT_SYS_CAP_INCLUDE, + "other.pkg.ExampleComponent", + "example_entity" + ); +}