Skip to content

Commit

Permalink
fix: allow fully qualified type name from other packages (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy authored Mar 7, 2023
1 parent ef59501 commit 4e019a5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
23 changes: 18 additions & 5 deletions ecsact/detail/grammar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,20 @@ struct whitespace {
lexy::dsl::inline_<line_comment> | lexy::dsl::inline_<block_comment>;
};

/**
* 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<std::string_view>;
};

/**
* Type name used for declaration
*/
struct type_name_decl {
static constexpr auto rule =
lexy::dsl::identifier(lexy::dsl::ascii::alpha, lexy::dsl::ascii::alnum);

Expand Down Expand Up @@ -179,7 +192,7 @@ struct component_statement {
};

static constexpr auto rule = lexy::dsl::p<component_keyword> >>
lexy::dsl::p<type_name>;
lexy::dsl::p<type_name_decl>;

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

static constexpr auto rule = lexy::dsl::p<transient_keyword> >>
lexy::dsl::p<type_name>;
lexy::dsl::p<type_name_decl>;

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

static constexpr auto rule = lexy::dsl::p<system_keyword> >>
lexy::dsl::opt(lexy::dsl::p<type_name>);
lexy::dsl::opt(lexy::dsl::p<type_name_decl>);

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

static constexpr auto rule = lexy::dsl::p<action_keyword> >>
lexy::dsl::p<type_name>;
lexy::dsl::p<type_name_decl>;

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

static constexpr auto rule = lexy::dsl::p<enum_keyword> >>
lexy::dsl::p<type_name>;
lexy::dsl::p<type_name_decl>;

static constexpr auto value =
lexy::callback<ecsact_statement>([](std::string_view enum_name) {
Expand Down
21 changes: 21 additions & 0 deletions test/parse_test_system_component_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

0 comments on commit 4e019a5

Please sign in to comment.