about summary refs log tree commit diff stats
path: root/050scenario.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-14 16:11:47 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-14 16:11:47 -0700
commit7fb3fccbb8f2a4b068a0e4bffa46a935e11db3a4 (patch)
treeefe99f8da8dc4f6e82cbd29c050f494cf832035f /050scenario.cc
parentb1bfd9213244d0da4c5d99ef3adcec121b041380 (diff)
downloadmu-7fb3fccbb8f2a4b068a0e4bffa46a935e11db3a4.tar.gz
1564 - a better way to support string literals
Our new heuristic is: all string literals are the same. If they contain
newline before non-whitespace, we scan for comments assuming there might
be code inside:

  foofoofoo [
    ...  # ']' inside comment ignored
  ]

If they contain non-whitespace first, then we ignore comments assuming
it's just a regular string:

  foofoofoo [abc#def]  # valid string literal

The big hole in this approach:

  foofoofoo [ # what about comments here containing ']'?
    ... # abc
  ]

Currently this reads as a 'code comment' and terminates before the
newline or '?' and will probably trigger errors down the line.
Temporary workaround: don't start code strings with a comment on the
same line as the '['. Eventually we'll tighten up the logic.

We're still not using the new heuristic in scenarios, but that's up
next.
Diffstat (limited to '050scenario.cc')
-rw-r--r--050scenario.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/050scenario.cc b/050scenario.cc
index bb828636..0f463cfc 100644
--- a/050scenario.cc
+++ b/050scenario.cc
@@ -74,6 +74,7 @@ scenario parse_scenario(istream& in) {
 //?   cerr << "parse scenario\n"; //? 1
   scenario result;
   result.name = next_word(in);
+//?   cerr << "scenario: " << result.name << '\n'; //? 1
   skip_whitespace_and_comments(in);
   assert(in.peek() == '[');
   // scenarios are take special 'code' strings so we need to ignore brackets
@@ -130,7 +131,7 @@ void run_mu_scenario(const scenario& s) {
     Trace_stream = new trace_stream;
     setup();
   }
-//?   cerr << '^' << s.to_run << "$\n"; //? 1
+//?   cerr << '^' << s.to_run << "$\n"; //? 2
   run("recipe "+s.name+" [ " + s.to_run + " ]");
   if (not_already_inside_test && Trace_stream) {
     teardown();
@@ -539,7 +540,7 @@ string slurp_quoted_ignoring_comments(istream& in) {
       // can't yet handle scenarios inside strings inside scenarios..
       in.putback(c);
       out << slurp_quoted(in);
-//?       cerr << "snapshot: ^" << out.str() << "$\n"; //? 1
+//?       cerr << "snapshot: ^" << out.str() << "$\n"; //? 2
       continue;
     }
     if (c == ']') {