about summary refs log tree commit diff stats
path: root/014literal_string.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-03-12 18:56:55 -0700
committerKartik Agaram <vc@akkartik.com>2019-03-12 19:14:12 -0700
commit4a943d4ed313eff001504c2b5c472266e86a38af (patch)
treea5757233a8c81b303a808f251180c7344071ed51 /014literal_string.cc
parent43711b0e9f18e0225ce14687fb6ea0902aa6fc61 (diff)
downloadmu-4a943d4ed313eff001504c2b5c472266e86a38af.tar.gz
5001 - drop the :(scenario) DSL
I've been saying for a while[1][2][3] that adding extra abstractions makes
things harder for newcomers, and adding new notations doubly so. And then
I notice this DSL in my own backyard. Makes me feel like a hypocrite.

[1] https://news.ycombinator.com/item?id=13565743#13570092
[2] https://lobste.rs/s/to8wpr/configuration_files_are_canary_warning
[3] https://lobste.rs/s/mdmcdi/little_languages_by_jon_bentley_1986#c_3miuf2

The implementation of the DSL was also highly hacky:

a) It was happening in the tangle/ tool, but was utterly unrelated to tangling
layers.

b) There were several persnickety constraints on the different kinds of
lines and the specific order they were expected in. I kept finding bugs
where the translator would silently do the wrong thing. Or the error messages
sucked, and readers may be stuck looking at the generated code to figure
out what happened. Fixing error messages would require a lot more code,
which is one of my arguments against DSLs in the first place: they may
be easy to implement, but they're hard to design to go with the grain of
the underlying platform. They require lots of iteration. Is that effort
worth prioritizing in this project?

On the other hand, the DSL did make at least some readers' life easier,
the ones who weren't immediately put off by having to learn a strange syntax.
There were fewer quotes to parse, fewer backslash escapes.

Anyway, since there are also people who dislike having to put up with strange
syntaxes, we'll call that consideration a wash and tear this DSL out.

---

This commit was sheer drudgery. Hopefully it won't need to be redone with
a new DSL because I grow sick of backslashes.
Diffstat (limited to '014literal_string.cc')
-rw-r--r--014literal_string.cc185
1 files changed, 117 insertions, 68 deletions
diff --git a/014literal_string.cc b/014literal_string.cc
index eb5422ff..84dbe8d0 100644
--- a/014literal_string.cc
+++ b/014literal_string.cc
@@ -6,18 +6,27 @@
 //: imagine that 'recipe' might one day itself be defined in Mu, doing its own
 //: parsing.
 
-:(scenarios load)
-:(scenario string_literal)
-def main [
-  1:address:array:character <- copy [abc def]
-]
-+parse:   ingredient: {"abc def": "literal-string"}
-
-:(scenario string_literal_with_colons)
-def main [
-  1:address:array:character <- copy [abc:def/ghi]
-]
-+parse:   ingredient: {"abc:def/ghi": "literal-string"}
+void test_string_literal() {
+  load(
+      "def main [\n"
+      "  1:address:array:character <- copy [abc def]\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse:   ingredient: {\"abc def\": \"literal-string\"}\n"
+  );
+}
+
+void test_string_literal_with_colons() {
+  load(
+      "def main [\n"
+      "  1:address:array:character <- copy [abc:def/ghi]\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse:   ingredient: {\"abc:def/ghi\": \"literal-string\"}\n"
+  );
+}
 
 :(before "End Mu Types Initialization")
 put(Type_ordinal, "literal-string", 0);
@@ -167,59 +176,99 @@ void slurp_one_past_backslashes(istream& in, ostream& out) {
   }
 }
 
-:(scenario string_literal_nested)
-def main [
-  1:address:array:character <- copy [abc [def]]
-]
-+parse:   ingredient: {"abc [def]": "literal-string"}
-
-:(scenario string_literal_escaped)
-def main [
-  1:address:array:character <- copy [abc \[def]
-]
-+parse:   ingredient: {"abc [def": "literal-string"}
-
-:(scenario string_literal_escaped_twice)
-def main [
-  1:address:array:character <- copy [
-abc \\[def]
-]
-+parse:   ingredient: {"\nabc \[def": "literal-string"}
-
-:(scenario string_literal_and_comment)
-def main [
-  1:address:array:character <- copy [abc]  # comment
-]
-+parse: --- defining main
-+parse: instruction: copy
-+parse:   number of ingredients: 1
-+parse:   ingredient: {"abc": "literal-string"}
-+parse:   product: {1: ("address" "array" "character")}
-
-:(scenario string_literal_escapes_newlines_in_trace)
-def main [
-  copy [abc
-def]
-]
-+parse:   ingredient: {"abc\ndef": "literal-string"}
-
-:(scenario string_literal_can_skip_past_comments)
-def main [
-  copy [
-    # ']' inside comment
-    bar
-  ]
-]
-+parse:   ingredient: {"\n    # ']' inside comment\n    bar\n  ": "literal-string"}
-
-:(scenario string_literal_empty)
-def main [
-  copy []
-]
-+parse:   ingredient: {"": "literal-string"}
-
-:(scenario multiple_unfinished_recipes)
-% Hide_errors = true;
-def f1 [
-def f2 [
-+error: unbalanced '['
+void test_string_literal_nested() {
+  load(
+      "def main [\n"
+      "  1:address:array:character <- copy [abc [def]]\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse:   ingredient: {\"abc [def]\": \"literal-string\"}\n"
+  );
+}
+
+void test_string_literal_escaped() {
+  load(
+      "def main [\n"
+      "  1:address:array:character <- copy [abc \\[def]\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse:   ingredient: {\"abc [def\": \"literal-string\"}\n"
+  );
+}
+
+void test_string_literal_escaped_twice() {
+  load(
+      "def main [\n"
+      "  1:address:array:character <- copy [\n"
+      "abc \\\\[def]\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse:   ingredient: {\"\\nabc \\[def\": \"literal-string\"}\n"
+  );
+}
+
+void test_string_literal_and_comment() {
+  load(
+      "def main [\n"
+      "  1:address:array:character <- copy [abc]  # comment\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse: --- defining main\n"
+      "parse: instruction: copy\n"
+      "parse:   number of ingredients: 1\n"
+      "parse:   ingredient: {\"abc\": \"literal-string\"}\n"
+      "parse:   product: {1: (\"address\" \"array\" \"character\")}\n"
+  );
+}
+
+void test_string_literal_escapes_newlines_in_trace() {
+  load(
+      "def main [\n"
+      "  copy [abc\n"
+      "def]\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse:   ingredient: {\"abc\\ndef\": \"literal-string\"}\n"
+  );
+}
+
+void test_string_literal_can_skip_past_comments() {
+  load(
+      "def main [\n"
+      "  copy [\n"
+      "    # ']' inside comment\n"
+      "    bar\n"
+      "  ]\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse:   ingredient: {\"\\n    # ']' inside comment\\n    bar\\n  \": \"literal-string\"}\n"
+  );
+}
+
+void test_string_literal_empty() {
+  load(
+      "def main [\n"
+      "  copy []\n"
+      "]\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "parse:   ingredient: {\"\": \"literal-string\"}\n"
+  );
+}
+
+void test_multiple_unfinished_recipes() {
+  Hide_errors = true;
+  load(
+      "def f1 [\n"
+      "def f2 [\n"
+  );
+  CHECK_TRACE_CONTENTS(
+      "error: unbalanced '['\n"
+  );
+}