-
Notifications
You must be signed in to change notification settings - Fork 130
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
Always include whitespace in string literals #688
Always include whitespace in string literals #688
Conversation
Signed-off-by: Shane Loretz <[email protected]>
@pablogs9 this seems to resolve the issue on my machine. Mind checking if it works for your use case? |
@sloretz LGTM, thanks a lot for this. Are you going to backport to humble? |
Signed-off-by: Shane Loretz <[email protected]>
I added tests for whitespace at the start and end of the string. With |
I think this change is backportable to humble. |
Linux CI failure is known to be flaky: ros2/rosbag2#862. CI LGTM! |
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
code changes are arcane, but the test cases make sense to me.
+1 for backporting, if anyone was relying on this behavior it was a bug and therefore I think it's ok to break them.
@Mergifyio backport humble galactic foxy |
* Always include whitespace in string literals Signed-off-by: Shane Loretz <[email protected]> * Add tests for #676 Signed-off-by: Shane Loretz <[email protected]> (cherry picked from commit 5181196)
* Always include whitespace in string literals Signed-off-by: Shane Loretz <[email protected]> * Add tests for #676 Signed-off-by: Shane Loretz <[email protected]> (cherry picked from commit 5181196)
* Always include whitespace in string literals Signed-off-by: Shane Loretz <[email protected]> * Add tests for #676 Signed-off-by: Shane Loretz <[email protected]> (cherry picked from commit 5181196)
✅ Backports have been created
|
* Always include whitespace in string literals Signed-off-by: Shane Loretz <[email protected]> * Add tests for #676 Signed-off-by: Shane Loretz <[email protected]> (cherry picked from commit 5181196) Co-authored-by: Shane Loretz <[email protected]>
* Always include whitespace in string literals Signed-off-by: Shane Loretz <[email protected]> * Add tests for #676 Signed-off-by: Shane Loretz <[email protected]> (cherry picked from commit 5181196) Co-authored-by: Shane Loretz <[email protected]>
* Always include whitespace in string literals Signed-off-by: Shane Loretz <[email protected]> * Add tests for #676 Signed-off-by: Shane Loretz <[email protected]> (cherry picked from commit 5181196) Co-authored-by: Shane Loretz <[email protected]>
Alternative to #677
Fixes #676
rosidl_parser
randomly ignores whitespace at the start of string literals. This example matches the string literal asToken('__ANON_6', ' e')
orToken('__ANON_6', 'e')
when run multiple times; however, stripping the whitespace is incorrect.I think the cause is a combination of ignoring whitespace
rosidl/rosidl_parser/rosidl_parser/grammar.lark
Line 18 in 0250ae8
and the way the
string_literal
rule is constructedrosidl/rosidl_parser/rosidl_parser/grammar.lark
Line 77 in 0250ae8
The
string_literal
rule has two parts. The first part matches an empty string""
, and the second part matches a non-empty string. The second part says to match three things. First match a quote"
. Next match at least one of: an escaped quote\"
, or a character that is not a quote. Finally match another quote"
. I think the problem is the second rule being divided into three parts. It ambiguous if the parser should ignore the whitespace between the first quote and the string content, or if it should include the whitespace via the not-a-quote regex.Lark has a built in rule for exactly this situation: https://github.com/lark-parser/lark/blob/953171821ed307f700fddf27f3fcb9483346bd46/lark/grammars/common.lark#L26-L29
We could
%import common.ESCAPED_STRING
forstring_literal
, butwhide_string_literal
probably has the same problem. If I definedwide_string_literal
as"L" ESCAPED_STRING
then it would also matchL "white space between L and first quote"
, which is also incorrect. I've chosen to copy the rules from lark into our grammar instead.There's a stackoverlow post explaining how lark's
ESCAPED_STRING
rule works: https://stackoverflow.com/a/61374198