about summary refs log tree commit diff stats
path: root/tangle/003tangle.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-07-25 14:41:48 -0700
committerKartik Agaram <vc@akkartik.com>2018-07-25 14:41:48 -0700
commita18f5328ebe8d5cb878c90bf9ca03c1ab864a7d2 (patch)
treeb6b0f3c857bcfb8be689563892048f6ffe32ded2 /tangle/003tangle.cc
parent05db3f68947ec49fae945b3f388b928e3d3aca05 (diff)
downloadmu-a18f5328ebe8d5cb878c90bf9ca03c1ab864a7d2.tar.gz
4405
Diffstat (limited to 'tangle/003tangle.cc')
-rw-r--r--tangle/003tangle.cc27
1 files changed, 17 insertions, 10 deletions
diff --git a/tangle/003tangle.cc b/tangle/003tangle.cc
index bc67051a..384af5e6 100644
--- a/tangle/003tangle.cc
+++ b/tangle/003tangle.cc
@@ -310,7 +310,7 @@ void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
       lines.pop_front();
     }
     if (lines.empty()) break;
-    result.push_back(input_lines(lines));
+    emit_input_lines(lines, result);
     emit_expected_in_trace(lines, result);
     while (!lines.empty() && !front(lines).contents.empty() && front(lines).contents.at(0) == '-') {
       result.push_back(expected_not_in_trace(front(lines)));
@@ -341,17 +341,24 @@ bool is_input(const string& line) {
   return line != "===" && line.find_first_of("+-$?%") != 0;
 }
 
-Line input_lines(list<Line>& hunk) {
+void emit_input_lines(list<Line>& hunk, list<Line>& out) {
   assert(!hunk.empty());
-  Line result;
-  result.line_number = hunk.front().line_number;
-  result.filename = hunk.front().filename;
-  while (!hunk.empty() && is_input(hunk.front().contents)) {
-    result.contents += hunk.front().contents+"";  // temporary delimiter; replace with escaped newline after escaping other backslashes
-    hunk.pop_front();
+  Line curr_out;
+  curr_out.line_number = hunk.front().line_number;
+  curr_out.filename = hunk.front().filename;
+  curr_out.contents = "  "+Toplevel+"(";
+  out.push_back(curr_out);
+  for (/*nada*/;  !hunk.empty() && is_input(front(hunk).contents);  hunk.pop_front()) {
+    Line curr_out;
+    curr_out.line_number = front(hunk).line_number;
+    curr_out.filename = front(hunk).filename;
+    curr_out.contents = "      \""+escape(front(hunk).contents+'')+"\"";
+    out.push_back(curr_out);
   }
-  result.contents = "  "+Toplevel+"(\""+escape(result.contents)+"\");";
-  return result;
+  curr_out.line_number = out.back().line_number;
+  curr_out.filename = out.back().filename;
+  curr_out.contents = "  );";
+  out.push_back(curr_out);
 }
 
 // pull lines starting with '+' out of 'hunk', and append translated lines to 'out'