-
Notifications
You must be signed in to change notification settings - Fork 125
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
Conversation
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), |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"]
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
This should be updated according to ros2/design#111 |
@mikaelarguedas look at this someday ! |
9afbd64
to
04d0532
Compare
236d717
to
c297959
Compare
…ke escaped IDL strings are broken in C++)
43ff7b9
to
9f2f54c
Compare
@@ -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!")); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in efe98ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
related to #206
to be merged along ros2/design#111
CI:![Build Status](https://camo.githubusercontent.com/3723c9d03bf5c9ece67764341900ecf5f4e6ce0812f68ee616e38a5ff8529dd5/687474703a2f2f63692e726f73322e6f72672f6275696c645374617475732f69636f6e3f6a6f623d63695f6c696e7578266275696c643d32313732)
![Build Status](https://camo.githubusercontent.com/908fdb27d059978dcb47f83ab4e1aef811388847cf009bb6cd22e635ad1f7996/687474703a2f2f63692e726f73322e6f72672f6275696c645374617475732f69636f6e3f6a6f623d63695f6f7378266275696c643d31363534)
![Build Status](https://camo.githubusercontent.com/850b44982f51b61e744370dd6f4d808b7c9f455d7da1b7af677901f87acafb73/687474703a2f2f63692e726f73322e6f72672f6275696c645374617475732f69636f6e3f6a6f623d63695f77696e646f7773266275696c643d32313734)
Linux:
OSX:
Windows: