about summary refs log tree commit diff stats
path: root/cpp/tangle/030tangle.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-29 11:45:43 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-29 11:45:43 -0700
commit4f5cf6683350f8ba9159c953a868b8d393bcd1ae (patch)
tree0b7fdee183f48f4c161afd3b18c653a7a8c4bea1 /cpp/tangle/030tangle.cc
parent519681dfe7abbe502918892b98deeb88597f4010 (diff)
downloadmu-4f5cf6683350f8ba9159c953a868b8d393bcd1ae.tar.gz
1220 - permit mu comments in tangle scenarios
Diffstat (limited to 'cpp/tangle/030tangle.cc')
-rw-r--r--cpp/tangle/030tangle.cc39
1 files changed, 24 insertions, 15 deletions
diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc
index f4b22f2b..944b12ef 100644
--- a/cpp/tangle/030tangle.cc
+++ b/cpp/tangle/030tangle.cc
@@ -95,26 +95,35 @@ void tangle(istream& in, list<Line>& out) {
 }
 
 void process_next_hunk(istream& in, const string& directive, const string& filename, size_t& line_number, list<Line>& out) {
+  istringstream directive_stream(directive.substr(2));  // length of ":("
+  string cmd = next_tangle_token(directive_stream);
+
+  // first slurp all lines until next directive
   list<Line> hunk;
-  string curr_line;
-  while (!in.eof()) {
-    std::streampos old = in.tellg();
-    getline(in, curr_line);
-    if (starts_with(curr_line, ":(")) {
-      in.seekg(old);
-      break;
-    }
-    if (starts_with(curr_line, "//:")) {
+  {
+    string curr_line;
+    while (!in.eof()) {
+      std::streampos old = in.tellg();
+      getline(in, curr_line);
+      if (starts_with(curr_line, ":(")) {
+        in.seekg(old);
+        break;
+      }
+      if (starts_with(curr_line, "//:")) {
+        // tangle comments
+        ++line_number;
+        continue;
+      }
+      if (cmd == "scenario" && starts_with(curr_line, "#")) {
+        // scenarios can contain mu comments
+        ++line_number;
+        continue;
+      }
+      hunk.push_back(Line(curr_line, filename, line_number));
       ++line_number;
-      continue;
     }
-    hunk.push_back(Line(curr_line, filename, line_number));
-    ++line_number;
   }
 
-  istringstream directive_stream(directive.substr(2));  // length of ":("
-  string cmd = next_tangle_token(directive_stream);
-
   if (cmd == "code") {
     out.insert(out.end(), hunk.begin(), hunk.end());
     return;