about summary refs log tree commit diff stats
path: root/011load.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 /011load.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 '011load.cc')
-rw-r--r--011load.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/011load.cc b/011load.cc
index 94f73634..7d9c3047 100644
--- a/011load.cc
+++ b/011load.cc
@@ -19,12 +19,14 @@ vector<recipe_number> load(string form) {
 vector<recipe_number> load(istream& in) {
   vector<recipe_number> result;
   while (!in.eof()) {
+//?     cerr << "===\n"; //? 1
     skip_whitespace_and_comments(in);
     if (in.eof()) break;
     string command = next_word(in);
     // Command Handlers
     if (command == "recipe") {
       string recipe_name = next_word(in);
+//?       cerr << "recipe: " << recipe_name << '\n'; //? 1
       if (recipe_name.empty())
         raise << "empty recipe name\n";
       if (Recipe_number.find(recipe_name) == Recipe_number.end()) {
@@ -60,6 +62,7 @@ recipe slurp_recipe(istream& in) {
   instruction curr;
   while (next_instruction(in, &curr)) {
     // End Rewrite Instruction(curr)
+//?     cerr << "instruction: " << curr.to_string() << '\n'; //? 2
     result.steps.push_back(curr);
   }
   return result;
@@ -102,6 +105,7 @@ bool next_instruction(istream& in, instruction* curr) {
     for (; *p != "<-"; ++p) {
       if (*p == ",") continue;
       curr->products.push_back(reagent(*p));
+//?       cerr << "product: " << curr->products.back().to_string() << '\n'; //? 1
     }
     ++p;  // skip <-
   }
@@ -119,6 +123,7 @@ bool next_instruction(istream& in, instruction* curr) {
   for (; p != words.end(); ++p) {
     if (*p == ",") continue;
     curr->ingredients.push_back(reagent(*p));
+//?     cerr << "ingredient: " << curr->ingredients.back().to_string() << '\n'; //? 1
   }
 
   trace("parse") << "instruction: " << curr->name;
@@ -138,6 +143,7 @@ string next_word(istream& in) {
   slurp_word(in, out);
   skip_whitespace(in);
   skip_comment(in);
+//?   cerr << '^' << out.str() << "$\n"; //? 1
   return out.str();
 }