about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--010vm.cc17
-rw-r--r--013literal_string.cc20
2 files changed, 20 insertions, 17 deletions
diff --git a/010vm.cc b/010vm.cc
index ecd2df23..ea0d6632 100644
--- a/010vm.cc
+++ b/010vm.cc
@@ -205,9 +205,6 @@ reagent::reagent() :value(0), initialized(false) {
 }
 
 string reagent::to_string() const {
-  if (!properties.at(0).second.empty() && properties.at(0).second.at(0) == "literal-string") {
-    return emit_literal_string(name);
-  }
   ostringstream out;
   out << "{name: \"" << name << "\"";
   if (!properties.empty()) {
@@ -227,20 +224,6 @@ string reagent::to_string() const {
   return out.str();
 }
 
-string emit_literal_string(string name) {
-  size_t pos = 0;
-  while (pos != string::npos)
-    pos = replace(name, "\n", "\\n", pos);
-  return "{name: \""+name+"\", properties: [_: \"literal-string\"]}";
-}
-
-size_t replace(string& str, const string& from, const string& to, size_t n) {
-  size_t result = str.find(from, n);
-  if (result != string::npos)
-    str.replace(result, from.length(), to);
-  return result;
-}
-
 string instruction::to_string() const {
   if (is_label) return label;
   ostringstream out;
diff --git a/013literal_string.cc b/013literal_string.cc
index 41644b1c..3d60a30f 100644
--- a/013literal_string.cc
+++ b/013literal_string.cc
@@ -69,6 +69,26 @@ string slurp_quoted(istream& in) {
     return;
   }
 
+:(after "string reagent::to_string()")
+  if (!properties.at(0).second.empty() && properties.at(0).second.at(0) == "literal-string") {
+    return emit_literal_string(name);
+  }
+
+:(code)
+string emit_literal_string(string name) {
+  size_t pos = 0;
+  while (pos != string::npos)
+    pos = replace(name, "\n", "\\n", pos);
+  return "{name: \""+name+"\", properties: [_: \"literal-string\"]}";
+}
+
+size_t replace(string& str, const string& from, const string& to, size_t n) {
+  size_t result = str.find(from, n);
+  if (result != string::npos)
+    str.replace(result, from.length(), to);
+  return result;
+}
+
 :(scenario string_literal_nested)
 recipe main [
   1:address:array:character <- copy [abc [def]]