summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgenerator/nanopb_generator.py9
-rw-r--r--tests/regression/issue_145/SConscript9
-rw-r--r--tests/regression/issue_145/comments.expected3
-rw-r--r--tests/regression/issue_145/comments.options6
-rw-r--r--tests/regression/issue_145/comments.proto5
5 files changed, 30 insertions, 2 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index eebe5404..b1ee04e0 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -4,6 +4,7 @@
nanopb_version = "nanopb-0.3.3-dev"
import sys
+import re
try:
# Add some dummy imports to keep packaging tools happy.
@@ -1164,9 +1165,13 @@ def read_options_file(infile):
[(namemask, options), ...]
'''
results = []
- for i, line in enumerate(infile):
+ data = infile.read()
+ data = re.sub('/\*.*?\*/', '', data, flags = re.MULTILINE)
+ data = re.sub('//.*?$', '', data, flags = re.MULTILINE)
+ data = re.sub('#.*?$', '', data, flags = re.MULTILINE)
+ for i, line in enumerate(data.split('\n')):
line = line.strip()
- if not line or line.startswith('//') or line.startswith('#'):
+ if not line:
continue
parts = line.split(None, 1)
diff --git a/tests/regression/issue_145/SConscript b/tests/regression/issue_145/SConscript
new file mode 100644
index 00000000..0b793a7a
--- /dev/null
+++ b/tests/regression/issue_145/SConscript
@@ -0,0 +1,9 @@
+# Regression test for Issue 145: Allow /* */ and // comments in .options files
+
+Import("env")
+
+env.NanopbProto(["comments", "comments.options"])
+env.Object('comments.pb.c')
+
+env.Match(['comments.pb.h', 'comments.expected'])
+
diff --git a/tests/regression/issue_145/comments.expected b/tests/regression/issue_145/comments.expected
new file mode 100644
index 00000000..7f874587
--- /dev/null
+++ b/tests/regression/issue_145/comments.expected
@@ -0,0 +1,3 @@
+char foo\[5\];
+char bar\[16\];
+
diff --git a/tests/regression/issue_145/comments.options b/tests/regression/issue_145/comments.options
new file mode 100644
index 00000000..89959ba2
--- /dev/null
+++ b/tests/regression/issue_145/comments.options
@@ -0,0 +1,6 @@
+/* Block comment */
+# Line comment
+// Line comment
+DummyMessage.foo /* Block comment */ max_size:5
+DummyMessage.bar max_size:16 # Line comment ###
+
diff --git a/tests/regression/issue_145/comments.proto b/tests/regression/issue_145/comments.proto
new file mode 100644
index 00000000..4e86b302
--- /dev/null
+++ b/tests/regression/issue_145/comments.proto
@@ -0,0 +1,5 @@
+message DummyMessage {
+ required string foo = 1;
+ required string bar = 2;
+}
+