xtypes icon indicating copy to clipboard operation
xtypes copied to clipboard

Annotations from idl parser

Open joakimono opened this issue 1 year ago • 0 comments

The eprosima::xtypes::Member has support for id, key and optional annotations, which can be set using the xtypes API. Currently, it seems the IDL parser do not parse annotations. Is it possible to slightly extend the grammar or the IDL parser implementation, so that the three annotations above are recognized when parsing IDL files?


  std::string my_idl = R"~~~(
    struct Inner
    {
        @key uint32 my_uint32;
        @optional boolean yes;
    };
  )~~~";

  eprosima::xtypes::idl::Context context = eprosima::xtypes::idl::parse(my_idl);

  // Create struct same with xtypes API
  eprosima::xtypes::StructType inner2 =
   eprosima::xtypes::StructType("Inner")
   .add_member(eprosima::xtypes::Member("my_uint32", eprosima::xtypes::primitive_type<uint32_t>()).key())
   .add_member(eprosima::xtypes::Member("yes", eprosima::xtypes::primitive_type<bool>()).optional());

  auto inner = context.module().structure("Inner");

  EXPECT_EQ(inner.member(0).is_key(), inner2.member(0).is_key());           // false, true
  EXPECT_EQ(inner.member(1).is_optional(), inner2.member(1).is_optional()); // false, true

joakimono avatar Jul 28 '23 14:07 joakimono