Improve comment support in .options files.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Fri, 3 Apr 2015 17:43:13 +0000 (20:43 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Fri, 3 Apr 2015 17:43:13 +0000 (20:43 +0300)
Update issue 145
Status: FixedInGit

generator/nanopb_generator.py
tests/regression/issue_145/SConscript [new file with mode: 0644]
tests/regression/issue_145/comments.expected [new file with mode: 0644]
tests/regression/issue_145/comments.options [new file with mode: 0644]
tests/regression/issue_145/comments.proto [new file with mode: 0644]

index eebe540..b1ee04e 100755 (executable)
@@ -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 (file)
index 0000000..0b793a7
--- /dev/null
@@ -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 (file)
index 0000000..7f87458
--- /dev/null
@@ -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 (file)
index 0000000..89959ba
--- /dev/null
@@ -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 (file)
index 0000000..4e86b30
--- /dev/null
@@ -0,0 +1,5 @@
+message DummyMessage {
+    required string foo = 1;
+    required string bar = 2;
+}
+