Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default values for string arrays #197

Merged
merged 26 commits into from
Jun 14, 2018
Merged

Conversation

mikaelarguedas
Copy link
Member

@mikaelarguedas mikaelarguedas commented Jan 3, 2017

related to #206
to be merged along ros2/design#111

CI:
Linux: Build Status
OSX: Build Status
Windows: Build Status

@mikaelarguedas mikaelarguedas added the in progress Actively being worked on (Kanban column) label Jan 3, 2017
@mikaelarguedas mikaelarguedas self-assigned this Jan 3, 2017
lines.append(' goto %s%s;' % (label_prefix, last_label_index))
abort_lines[0:0] = [
' rosidl_generator_c__String__fini(&msg->%s[%d]);' % (field.name, i),
'%s%d:' % (label_prefix, last_label_index),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation not a multiple of 4.

lines.append(' goto %s%s;' % (label_prefix, last_label_index))
abort_lines[0:0] = [
' rosidl_generator_c__String__fini(&msg->%s.data[%d]);' % (field.name, i),
'%s%d:' % (label_prefix, last_label_index),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation not a multiple of 4.

@@ -445,8 +445,7 @@ def parse_value_string(type_, value_string):
if type_.is_primitive_type() and not type_.is_array:
return parse_primitive_value_string(type_, value_string)

# TODO(mikaelarguedas) change this condition once string escape function is implemented
if type_.is_primitive_type() and type_.is_array and type_.type != 'string':
if type_.is_primitive_type() and type_.is_array:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this just enables default values for string arrays but without implementing the required string escaping logic? Currently I simply splits on commas - I don't think this is sufficient since the comma can be within a string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry this is still work in progress, the strings are not escaped yet. This is also the case for simple strings. e.g. string def_string 'Hello w"orld!' makes the message generation crash (at least the python generator).

For string arrays it gets even trickier because the design document says that:
string: a string value which can optionally be quoted with either single quotes (') or double quotes (")
We need to make the quoting mandatory to allow differentiation of array elements otherwise it'll be ambiguous

Copy link
Member

@dirk-thomas dirk-thomas Jan 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the quoting need to mandatory? It should be possible to parse the following without a problem:

string[] names ['foo', "bar", 'foo"bar', 'bar\'baz', "foo'bar\"baz"]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we allow to not quote strings it is valid to declare:
string name a, b
this results in a string containing "a, b" and is totally valid.

Using the same logic for arrays it's valid to declare:
string[] names [a, b, c, d]
in that case we don't know if it's a single element containing `"a, b, c, d" or four element separated by commas or any other combination.
That's what I meant by making the quoting mandatory. Otherwise we'd need to define a delimiter that is not allowed in strings which doesn't make much sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we do know what the default values should be in that case. Since the individual items are not quoted the default value contains an array with four elements. Otherwise they would need to be quoted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is only for the message definition files right? I don't see what the command line has to do with this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to write only one parser and not multiple for different use cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, but I still feel that keeping the idl format as simple as possible will be best because we'll likely want to parse it in other languages at some point.

It's the difference in strings for JSON and strings for YAML. YAML is nice, but it's also complicated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think allowing single quotes is unnecessarily burdensome, so I'm fine with that, I was just trying to find ways to keep is simple. But not requiring the quotes seems unnecessary to me. For ROS 1, we use yaml syntax on the command line (which worked really well and allowed us to only specify parts of the message). So, if we use that again, I don't think we need a super flexible parser that can work here and on any arbitrary input from the CLI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @wjwwood that it would be simpler and clearer if we require users to quote and escape the interior quotes. Not only to reduce parser complexity but also improve human readability.

I agree that it all comes down to how (what format) we expect people to pass parameters (both CLI and IDL/config files). Do we have a document or discussion somewhere so that we could iterate on and refer to before making a decision on the scope of this parser?

@mikaelarguedas mikaelarguedas changed the title Support default values for string arrays Support default values for string arrays Jan 9, 2017
@mikaelarguedas mikaelarguedas added ready Work is about to start (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Jan 9, 2017
@mikaelarguedas
Copy link
Member Author

This should be updated according to ros2/design#111

@mikaelarguedas
Copy link
Member Author

@mikaelarguedas look at this someday !

@mikaelarguedas
Copy link
Member Author

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

CI testing only rosidl_parser with the linter fixup:

  • Linux Build Status
  • Windows Build Status

@mikaelarguedas mikaelarguedas added in review Waiting for review (Kanban column) and removed ready Work is about to start (Kanban column) labels Jun 13, 2018
@@ -295,6 +310,10 @@ int test_strings(void)
EXPECT_EQ(true, res);
EXPECT_EQ(0, strcmp(strings->empty_string.data, TEST_STRING));
EXPECT_EQ(0, strcmp(strings->def_string.data, "Hello world!"));
EXPECT_EQ(0, strcmp(strings->def_string2.data, "Hello'world!"));
EXPECT_EQ(0, strcmp(strings->def_string3.data, "Hello\"world!"));
EXPECT_EQ(0, strcmp(strings->def_string4.data, "Hello\'world!"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the message definition:

string def_string4 'Hello'world!'

Why is there a backslash in the C++ string literal? Should it be just "Hello'world!"?

Same for def_various_quotes.data[1].data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm good question. I guess as the escaping is not necessary in C because we use double quotes it should get "unescaped" by the C generator when it gets it from the parser

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra backslash should be removed then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in efe98ea

Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mikaelarguedas mikaelarguedas merged commit 6549399 into master Jun 14, 2018
@mikaelarguedas mikaelarguedas deleted the string_arrays_default branch June 14, 2018 04:27
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants