about summary refs log tree commit diff stats
path: root/013literal_string.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-19 13:37:11 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-19 13:37:11 -0700
commitfc52705f4956df9a756b902b187f31799c1451a4 (patch)
tree634a3dc201a2fb32a00f1ab9ae50b6818fd99732 /013literal_string.cc
parent8fb0e672c2f5431141d58128f623d1cc02d67bb8 (diff)
downloadmu-fc52705f4956df9a756b902b187f31799c1451a4.tar.gz
1598
Some tests weren't actually running for the past 5 days.
Performed 5 why's.
Diffstat (limited to '013literal_string.cc')
-rw-r--r--013literal_string.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/013literal_string.cc b/013literal_string.cc
index 60fbd266..f8445c26 100644
--- a/013literal_string.cc
+++ b/013literal_string.cc
@@ -62,10 +62,12 @@ bool code_string(istream& in, ostringstream& out) {
 
 // Read a regular string. Regular strings can only contain other regular
 // strings.
-void slurp_quoted_comment_oblivious(istream& in, ostream& out) {
+void slurp_quoted_comment_oblivious(istream& in, ostringstream& out) {
+//?   cerr << "comment oblivious\n"; //? 1
   int brace_depth = 1;
   while (!in.eof()) {
     char c = in.get();
+//?     cerr << '%' << (int)c << ' ' << brace_depth << ": " << out.str() << "%$\n"; //? 1
 //?     cout << (int)c << ": " << brace_depth << '\n'; //? 2
     if (c == '\\') {
       out << static_cast<char>(in.get());
@@ -84,9 +86,15 @@ void slurp_quoted_comment_oblivious(istream& in, ostream& out) {
 }
 
 // Read a code string. Code strings can contain either code or regular strings.
-void slurp_quoted_comment_aware(istream& in, ostream& out) {
+void slurp_quoted_comment_aware(istream& in, ostringstream& out) {
+//?   cerr << "comment aware\n"; //? 1
   char c;
   while (in >> c) {
+//?     cerr << '^' << (int)c << ": " << out.str() << "$\n"; //? 1
+    if (c == '\\') {
+      out << static_cast<char>(in.get());
+      continue;
+    }
     if (c == '#') {
       out << c;
       while (!in.eof() && in.peek() != '\n') out << static_cast<char>(in.get());
@@ -99,8 +107,10 @@ void slurp_quoted_comment_aware(istream& in, ostream& out) {
       continue;
     }
     out << c;
-    if (c == ']') break;
+    if (c == ']') return;
   }
+  raise << "unbalanced '['\n";
+  out.clear();
 }
 
 :(after "reagent::reagent(string s)")
@@ -154,6 +164,13 @@ recipe main [
 ]
 +parse:   ingredient: {name: "abc [def", properties: [_: "literal-string"]}
 
+:(scenario string_literal_escaped_comment_aware)
+recipe main [
+  1:address:array:character <- copy [
+abc \\\[def]
+]
++parse:   ingredient: {name: "\nabc \[def", properties: [_: "literal-string"]}
+
 :(scenario string_literal_and_comment)
 recipe main [
   1:address:array:character <- copy [abc]  # comment