Skip to content

Commit ab4f1d6

Browse files
authored
Allow forward slashes within a parameter name rule in argument parsing (#860)
* Allow forward slashes within a parameter name rule in argument parsing Signed-off-by: Ivan Santiago Paunovic <[email protected]>
1 parent d5baf85 commit ab4f1d6

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

rcl/src/rcl/arguments.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,45 @@ _rcl_parse_resource_match(
12481248
return RCL_RET_OK;
12491249
}
12501250

1251+
RCL_LOCAL
1252+
rcl_ret_t
1253+
_rcl_parse_param_name_token(rcl_lexer_lookahead2_t * lex_lookahead)
1254+
{
1255+
rcl_ret_t ret;
1256+
rcl_lexeme_t lexeme;
1257+
1258+
// Check arguments sanity
1259+
assert(NULL != lex_lookahead);
1260+
1261+
ret = rcl_lexer_lookahead2_peek(lex_lookahead, &lexeme);
1262+
if (RCL_RET_OK != ret) {
1263+
return ret;
1264+
}
1265+
if (RCL_LEXEME_TOKEN != lexeme && RCL_LEXEME_FORWARD_SLASH != lexeme) {
1266+
if (RCL_LEXEME_WILD_ONE == lexeme) {
1267+
RCL_SET_ERROR_MSG("Wildcard '*' is not implemented");
1268+
return RCL_RET_ERROR;
1269+
} else if (RCL_LEXEME_WILD_MULTI == lexeme) {
1270+
RCL_SET_ERROR_MSG("Wildcard '**' is not implemented");
1271+
return RCL_RET_ERROR;
1272+
} else {
1273+
RCL_SET_ERROR_MSG("Expecting token or wildcard");
1274+
return RCL_RET_WRONG_LEXEME;
1275+
}
1276+
}
1277+
do {
1278+
ret = rcl_lexer_lookahead2_accept(lex_lookahead, NULL, NULL);
1279+
if (RCL_RET_OK != ret) {
1280+
return ret;
1281+
}
1282+
ret = rcl_lexer_lookahead2_peek(lex_lookahead, &lexeme);
1283+
if (RCL_RET_OK != ret) {
1284+
return ret;
1285+
}
1286+
} while (RCL_LEXEME_TOKEN == lexeme || RCL_LEXEME_FORWARD_SLASH == lexeme);
1287+
return RCL_RET_OK;
1288+
}
1289+
12511290
/// Parse a parameter name in a parameter override rule (ex: `foo.bar`)
12521291
/**
12531292
* \sa _rcl_parse_param_rule()
@@ -1277,7 +1316,7 @@ _rcl_parse_param_name(
12771316
}
12781317

12791318
// token ( '.' token )*
1280-
ret = _rcl_parse_resource_match_token(lex_lookahead);
1319+
ret = _rcl_parse_param_name_token(lex_lookahead);
12811320
if (RCL_RET_OK != ret) {
12821321
return ret;
12831322
}
@@ -1290,7 +1329,7 @@ _rcl_parse_param_name(
12901329
if (RCL_RET_WRONG_LEXEME == ret) {
12911330
return RCL_RET_INVALID_REMAP_RULE;
12921331
}
1293-
ret = _rcl_parse_resource_match_token(lex_lookahead);
1332+
ret = _rcl_parse_param_name_token(lex_lookahead);
12941333
if (RCL_RET_OK != ret) {
12951334
return ret;
12961335
}

rcl/test/rcl/test_arguments.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,15 @@ TEST_F(CLASSNAME(TestArgumentsFixture, RMW_IMPLEMENTATION), check_known_vs_unkno
149149
EXPECT_TRUE(are_known_ros_args({"--ros-args", "-r", "rostopic:///rosservice:=rostopic"}));
150150
EXPECT_TRUE(are_known_ros_args({"--ros-args", "-r", "rostopic:///foo/bar:=baz"}));
151151
EXPECT_TRUE(are_known_ros_args({"--ros-args", "-p", "foo:=bar"}));
152+
// TODO(ivanpauno): Currently, we're accepting `/`, as they're being accepted by qos overrides.
153+
// We might need to revisit qos overrides parameters names if ROS 2 URIs get
154+
// modified.
155+
EXPECT_TRUE(
156+
are_known_ros_args(
157+
{"--ros-args", "-p", "qos_overrides./foo/bar.publisher.history:=keep_last"}));
152158
// TODO(hidmic): restore tests (and drop the following ones) when parameter names
153159
// are standardized to use slashes in lieu of dots.
154160
// EXPECT_TRUE(are_known_ros_args({"--ros-args", "-p", "~/foo:=~/bar"}));
155-
// EXPECT_TRUE(are_known_ros_args({"--ros-args", "-p", "/foo/bar:=bar"}));
156161
// EXPECT_TRUE(are_known_ros_args({"--ros-args", "-p", "foo:=/bar"}));
157162
// EXPECT_TRUE(are_known_ros_args({"--ros-args", "-p", "/foo123:=/bar123"}));
158163
EXPECT_TRUE(are_known_ros_args({"--ros-args", "-p", "foo.bar:=bar"}));

0 commit comments

Comments
 (0)