about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-17 12:13:49 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-17 12:13:49 -0700
commit5b0a415f113d00478f5a306988bbcdbd35d99094 (patch)
tree8af8df8874489e64bc39c83b1b6e3b7c67acdc52
parent2199940af170456929a3c4fe4d07d25afea6ae55 (diff)
downloadmu-5b0a415f113d00478f5a306988bbcdbd35d99094.tar.gz
1078 - better line numbers
Skip tangle comments inside tangle rather than in the makefile.
-rw-r--r--cpp/makefile2
-rw-r--r--cpp/tangle/030tangle.cc8
-rw-r--r--cpp/tangle/030tangle.test.cc16
3 files changed, 25 insertions, 1 deletions
diff --git a/cpp/makefile b/cpp/makefile
index b062b288..c9fd139f 100644
--- a/cpp/makefile
+++ b/cpp/makefile
@@ -4,7 +4,7 @@ mu: makefile enumerate/enumerate tangle/tangle mu.cc
 # To see what the program looks like after all layers have been applied, read
 # mu.cc
 mu.cc: 0*
-	./tangle/tangle $$(./enumerate/enumerate --until 999 |grep -v '.mu$$') |grep -v "^\s*//:" > mu.cc
+	./tangle/tangle $$(./enumerate/enumerate --until 999 |grep -v '.mu$$') > mu.cc
 	cat $$(./enumerate/enumerate --until 999 |grep '.mu$$') > core.mu
 	@make autogenerated_lists >/dev/null
 
diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc
index adbf925b..896e8f3e 100644
--- a/cpp/tangle/030tangle.cc
+++ b/cpp/tangle/030tangle.cc
@@ -1,3 +1,7 @@
+// Reorder a file based on directives starting with ':(' (tangle directives).
+// Insert #line directives to preserve line numbers in the original.
+// Clear lines starting with '//:' (tangle comments).
+
 #include<assert.h>
 #include<sys/param.h>
 
@@ -28,6 +32,10 @@ void tangle(istream& in, list<string>& out) {
     else
       out.push_back(curr_line);
   }
+  for (list<string>::iterator p = out.begin(); p != out.end(); ++p) {
+    if (starts_with(*p, "//:"))
+      p->clear();  // leave the empty lines around so as to not mess up #line numbers
+  }
   trace_all("tangle", out);
 }
 
diff --git a/cpp/tangle/030tangle.test.cc b/cpp/tangle/030tangle.test.cc
index 4aab6316..3f86fdb8 100644
--- a/cpp/tangle/030tangle.test.cc
+++ b/cpp/tangle/030tangle.test.cc
@@ -48,6 +48,22 @@ void test_tangle_with_multiple_filenames_after() {
 //?   exit(0); //? 1
 }
 
+void test_tangle_skip_tanglecomments() {
+  istringstream in("a\nb\nc\n//: 1\n//: 2\nd\n");
+  list<string> dummy;
+  tangle(in, dummy);
+  CHECK_TRACE_CONTENTS("tangle", "abcd");
+  CHECK_TRACE_DOESNT_CONTAIN("tangle", "//: 1");
+}
+
+void test_tangle_with_tanglecomments_and_directive() {
+  istringstream in("a\n//: 1\nb\nc\n:(before b)\nd\n:(code)\ne\n");
+  list<string> dummy;
+  tangle(in, dummy);
+  CHECK_TRACE_CONTENTS("tangle", "a#line 6d#line 3bc#line 8e");
+  CHECK_TRACE_DOESNT_CONTAIN("tangle", "//: 1");
+}
+
 void test_tangle2() {
   istringstream in("a\nb\nc\n:(after b)\nd\n");
   list<string> dummy;