about summary refs log tree commit diff stats
path: root/subx/038---literal_strings.cc
diff options
context:
space:
mode:
authornc <nc@charliethe.ninja>2019-04-13 19:58:36 -0400
committernc <nc@charliethe.ninja>2019-04-13 22:07:48 -0400
commit1209ddac2b17242a001c257e661973c050d6b2e4 (patch)
tree21c62ac450e69fd4b1dc98b545860767101bed1e /subx/038---literal_strings.cc
parentebb4f558699a325afc234b5125bce0d02aee370a (diff)
downloadmu-1209ddac2b17242a001c257e661973c050d6b2e4.tar.gz
Add support for escape sequences in string literals fixed traces so they can handle newlines
Diffstat (limited to 'subx/038---literal_strings.cc')
-rw-r--r--subx/038---literal_strings.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/subx/038---literal_strings.cc b/subx/038---literal_strings.cc
index b7cb0aa4..19ed2690 100644
--- a/subx/038---literal_strings.cc
+++ b/subx/038---literal_strings.cc
@@ -77,11 +77,11 @@ void add_global_to_data_segment(const string& name, const word& value, segment&
 
 void test_instruction_with_string_literal() {
   parse_instruction_character_by_character(
-      "a \"abc  def\" z\n"  // two spaces inside string
+      "a \"abc  def\\nwee\" z\n"  // two spaces inside string
   );
   CHECK_TRACE_CONTENTS(
       "parse2: word: a\n"
-      "parse2: word: \"abc  def\"\n"
+      "parse2: word: \"abc  def\\nwee\"\n"
       "parse2: word: z\n"
   );
   // no other words
@@ -123,7 +123,18 @@ void parse_instruction_character_by_character(const string& line_data, vector<li
       d << c;
       while (has_data(in)) {
         in >> c;
-        d << c;
+        if(c == '\\') {
+          in >> c;
+          if(c == 'n') d << '\n';
+          else if(c == 't') d << '\t';
+          else if(c == '"') d << '"';
+          else {
+            raise << "parse_instruction_character_by_character: unknown escape sequence '\\" << c << "'\n" << end();
+            return;
+          }
+        } else {
+          d << c;
+        }
         if (c == '"') break;
       }
       result.words.back().data = d.str();