diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2022-11-23 15:01:05 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2022-11-23 15:13:07 +0300 |
commit | eeda15ed4e899cd3d404abf74c1d60e50eb6f790 (patch) | |
tree | 1a1039b01a07863ca1cd08e1d5b20a3859d9926a | |
parent | d7b2747d946376ec29886eca2ecc6a4ae1fda4fe (diff) |
Sanitize /* */ inside .proto file comment
Otherwise ends up as a nested C comment, which does not compile.
-rwxr-xr-x | generator/nanopb_generator.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index f4b8a22..cf0642a 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -368,6 +368,13 @@ class ProtoElement(object): '''Get comments for a member of enum or message.''' return self.get_comments((ProtoElement.FIELD, index), leading_indent = True) + def format_comment(self, comment): + '''Put comment inside /* */ and sanitize comment contents''' + comment = comment.strip() + comment = comment.replace('/*', '/ *') + comment = comment.replace('*/', '* /') + return "/* %s */" % comment + def get_comments(self, member_path = (), leading_indent = False): '''Get leading & trailing comments for a protobuf element. @@ -388,10 +395,10 @@ class ProtoElement(object): if comment.leading_comments: leading_comment = " " if leading_indent else "" - leading_comment += "/* %s */" % comment.leading_comments.strip() + leading_comment += self.format_comment(comment.leading_comments) if comment.trailing_comments: - trailing_comment = "/* %s */" % comment.trailing_comments.strip() + trailing_comment = self.format_comment(comment.trailing_comments) return leading_comment, trailing_comment |