about summary refs log tree commit diff stats
path: root/cpp/029string
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-30 21:22:29 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-30 21:22:29 -0700
commit66b97b4d923274e1b6d2fd97df16cb73d820169b (patch)
tree9d05c3e8301381608d9619eae976c5459fbfa5d2 /cpp/029string
parenta7b6abf6262c1ac556c2cf9a5890eccb4d6b6872 (diff)
downloadmu-66b97b4d923274e1b6d2fd97df16cb73d820169b.tar.gz
996 - string literals
Diffstat (limited to 'cpp/029string')
-rw-r--r--cpp/029string29
1 files changed, 29 insertions, 0 deletions
diff --git a/cpp/029string b/cpp/029string
new file mode 100644
index 00000000..4379c8ec
--- /dev/null
+++ b/cpp/029string
@@ -0,0 +1,29 @@
+:(scenario "string_literal")
+recipe main [
+  s:address:array:character <- new [abc def]
+]
++parse:   ingredient: {name: "abc def", value: 0, type: 0, properties: [abc def: literal-string]}
+
+:(before "End Mu Types Initialization")
+Type_number["literal-string"] = 0;
+
+:(after "string next_word(istream& in)")
+if (in.peek() == '[') return slurp_quoted(in);
+
+:(code)
+string slurp_quoted(istream& in) {
+  assert(!in.eof());
+  assert(in.get() == '[');
+  ostringstream out;
+  int size = 1;
+  while (!in.eof()) {
+    char c = in.get();
+    if (c == '[') ++size;
+    if (c == ']') --size;
+    if (size == 0) break;
+//?     cout << c << '\n'; //? 1
+    out << c;
+//?     cout << out.str() << "$\n"; //? 1
+  }
+  return out.str();
+}