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

The proto2cpp.py regex for replacing . with :: can clobber natural punctuation in comments #8

Open
szmoore opened this issue Dec 30, 2020 · 0 comments
Labels
bug Problems in the build system, build scripts, etc or faults in the interface.

Comments

@szmoore
Copy link

szmoore commented Dec 30, 2020

Describe the bug

All full stops (periods) '.' occurring in comments are replaced with :: even when they don't result in a reference.

Describe how to reproduce the bug

Steps to reproduce the behavior:

  1. Write the following documentation string:
/**
 * This documentation is quite long.
 *
 * It needs more than once sentence to describe what is happening.
 * 
 * FullyStopped.value is a reference, but FullyStopped.
 *                                  value is not.
 */
message  FullyStopped {
    required uint32 value = 1;
};
  1. Generate documentation:
<detaileddescription>
  <para>This documentation is quite long::</para>
  <para>It needs more than once sentence to describe what is happening::</para>
  <para>
    <ref refid="structFullyStopped_1a8defeb7fb78806a0c55bfec7b89e6500" kindref="member">FullyStopped::value</ref> 
       is a reference, but <ref refid="structFullyStopped" kindref="compound">FullyStopped</ref>:: value is not:: </para>    </detaileddescription>

Converted to markdown for readability:

This documentation is quite long::

It needs more than once sentence to describe what is happening::

FullyStopped::value is a reference, but FullyStopped:: value is not

Describe the expected behavior

'.' characters should not be replaced if they are not followed by a set of non-whitespace characters

This documentation is quite long.

It needs more than once sentence to describe what is happening.

FullyStopped::value is a reference, but FullyStopped. value is not

Show some screenshots

Not Applicable

Describe the OS you are using

Additional context

A patch:

The (\S+) group requires the . to be followed by at least one (1) non whitespace character.

Any whitespace following a :: would be invalid syntax in C++ anyway, so I don't think this would break that many intentional references. Considering a sentence not followed by white space, like this one.I believe that would be invalid syntax in English.

diff --git a/proto2cpp.py b/proto2cpp.py
index a355aaa..6f0d80a 100644
--- a/proto2cpp.py
+++ b/proto2cpp.py
@@ -183,7 +183,8 @@ class proto2cpp:
         isMultilineComment = False
 
       # line = line.replace(".", "::") but not in quoted strings (Necessary for import statement)
-      line = re.sub(r'\.(?=(?:[^"]*"[^"]*")*[^"]*$)',r'::',line)
+      # also not if the "." was the final character in the line or was followed by whitespace (natural punctuation)
+      line = re.sub(r'\.(?=(?:[^"]*"[^"]*")*[^"]*$)(\S+)',r'::\1',line)
 
       # Search for " option ...;", remove it
       line = re.sub(r'\boption\b[^;]+;', r'', line)
@szmoore szmoore added the bug Problems in the build system, build scripts, etc or faults in the interface. label Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Problems in the build system, build scripts, etc or faults in the interface.
Projects
None yet
Development

No branches or pull requests

1 participant