From 9e751bb8c0cdf771d34c839cb6591d892b8e62de Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 7 Mar 2017 01:41:48 -0800 Subject: 3761 --- html/011load.cc.html | 201 ++++++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 100 deletions(-) (limited to 'html/011load.cc.html') diff --git a/html/011load.cc.html b/html/011load.cc.html index 5aeeb12e..3c89e1a6 100644 --- a/html/011load.cc.html +++ b/html/011load.cc.html @@ -16,16 +16,17 @@ a { text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .Constant { color: #00a0a0; } +.muRecipe { color: #ff8700; } +.Conceal { color: #4e4e4e; } .traceAbsent { color: #c00000; } .Special { color: #c00000; } -.muRecipe { color: #ff8700; } -.cSpecial { color: #008000; } .Comment { color: #9090ff; } .Delimiter { color: #800080; } .LineNr { color: #444444; } -.traceContains { color: #008000; } -.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Identifier { color: #c0a020; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } +.cSpecial { color: #008000; } +.traceContains { color: #008000; } --> @@ -85,28 +86,28 @@ if ('onhashchange' in window) { 23 in >> std::noskipws; 24 vector<recipe_ordinal> result; 25 while (has_data(in)) { - 26 skip_whitespace_and_comments(in); - 27 if (!has_data(in)) break; - 28 string command = next_word(in); - 29 if (command.empty()) { - 30 assert(!has_data(in)); - 31 break; - 32 } - 33 // Command Handlers - 34 if (command == "recipe" || command == "def") { - 35 recipe_ordinal r = slurp_recipe(in); - 36 if (r > 0) result.push_back(r); - 37 } - 38 else if (command == "recipe!" || command == "def!") { - 39 Disable_redefine_checks = true; - 40 recipe_ordinal r = slurp_recipe(in); - 41 if (r > 0) result.push_back(r); - 42 Disable_redefine_checks = false; - 43 } - 44 // End Command Handlers - 45 else { - 46 raise << "unknown top-level command: " << command << '\n' << end(); - 47 } + 26 ¦ skip_whitespace_and_comments(in); + 27 ¦ if (!has_data(in)) break; + 28 ¦ string command = next_word(in); + 29 ¦ if (command.empty()) { + 30 ¦ ¦ assert(!has_data(in)); + 31 ¦ ¦ break; + 32 ¦ } + 33 ¦ // Command Handlers + 34 ¦ if (command == "recipe" || command == "def") { + 35 ¦ ¦ recipe_ordinal r = slurp_recipe(in); + 36 ¦ ¦ if (r > 0) result.push_back(r); + 37 ¦ } + 38 ¦ else if (command == "recipe!" || command == "def!") { + 39 ¦ ¦ Disable_redefine_checks = true; + 40 ¦ ¦ recipe_ordinal r = slurp_recipe(in); + 41 ¦ ¦ if (r > 0) result.push_back(r); + 42 ¦ ¦ Disable_redefine_checks = false; + 43 ¦ } + 44 ¦ // End Command Handlers + 45 ¦ else { + 46 ¦ ¦ raise << "unknown top-level command: " << command << '\n' << end(); + 47 ¦ } 48 } 49 return result; 50 } @@ -116,23 +117,23 @@ if ('onhashchange' in window) { 54 recipe result; 55 result.name = next_word(in); 56 if (result.name.empty()) { - 57 assert(!has_data(in)); - 58 raise << "file ended with 'recipe'\n" << end(); - 59 return -1; + 57 ¦ assert(!has_data(in)); + 58 ¦ raise << "file ended with 'recipe'\n" << end(); + 59 ¦ return -1; 60 } 61 // End Load Recipe Name 62 skip_whitespace_but_not_newline(in); 63 // End Recipe Refinements 64 if (result.name.empty()) - 65 raise << "empty result.name\n" << end(); + 65 ¦ raise << "empty result.name\n" << end(); 66 trace(9991, "parse") << "--- defining " << result.name << end(); 67 if (!contains_key(Recipe_ordinal, result.name)) - 68 put(Recipe_ordinal, result.name, Next_recipe_ordinal++); + 68 ¦ put(Recipe_ordinal, result.name, Next_recipe_ordinal++); 69 if (Recipe.find(get(Recipe_ordinal, result.name)) != Recipe.end()) { - 70 trace(9991, "parse") << "already exists" << end(); - 71 if (should_check_for_redefine(result.name)) - 72 raise << "redefining recipe " << result.name << "\n" << end(); - 73 Recipe.erase(get(Recipe_ordinal, result.name)); + 70 ¦ trace(9991, "parse") << "already exists" << end(); + 71 ¦ if (should_check_for_redefine(result.name)) + 72 ¦ ¦ raise << "redefining recipe " << result.name << "\n" << end(); + 73 ¦ Recipe.erase(get(Recipe_ordinal, result.name)); 74 } 75 slurp_body(in, result); 76 // End Recipe Body(result) @@ -144,14 +145,14 @@ if ('onhashchange' in window) { 82 in >> std::noskipws; 83 skip_whitespace_but_not_newline(in); 84 if (in.get() != '[') - 85 raise << result.name << ": recipe body must begin with '['\n" << end(); + 85 ¦ raise << result.name << ": recipe body must begin with '['\n" << end(); 86 skip_whitespace_and_comments(in); // permit trailing comment after '[' 87 instruction curr; 88 while (next_instruction(in, &curr)) { - 89 curr.original_string = to_original_string(curr); - 90 // End Rewrite Instruction(curr, recipe result) - 91 trace(9992, "load") << "after rewriting: " << to_string(curr) << end(); - 92 if (!curr.is_empty()) result.steps.push_back(curr); + 89 ¦ curr.original_string = to_original_string(curr); + 90 ¦ // End Rewrite Instruction(curr, recipe result) + 91 ¦ trace(9992, "load") << "after rewriting: " << to_string(curr) << end(); + 92 ¦ if (!curr.is_empty()) result.steps.push_back(curr); 93 } 94 } 95 @@ -159,67 +160,67 @@ if ('onhashchange' in window) { 97 curr->clear(); 98 skip_whitespace_and_comments(in); 99 if (!has_data(in)) { -100 raise << "incomplete recipe at end of file (0)\n" << end(); -101 return false; +100 ¦ raise << "incomplete recipe at end of file (0)\n" << end(); +101 ¦ return false; 102 } 103 104 vector<string> words; 105 while (has_data(in) && in.peek() != '\n') { -106 skip_whitespace_but_not_newline(in); -107 if (!has_data(in)) { -108 raise << "incomplete recipe at end of file (1)\n" << end(); -109 return false; -110 } -111 string word = next_word(in); -112 if (word.empty()) { -113 assert(!has_data(in)); -114 raise << "incomplete recipe at end of file (2)\n" << end(); -115 return false; -116 } -117 words.push_back(word); -118 skip_whitespace_but_not_newline(in); +106 ¦ skip_whitespace_but_not_newline(in); +107 ¦ if (!has_data(in)) { +108 ¦ ¦ raise << "incomplete recipe at end of file (1)\n" << end(); +109 ¦ ¦ return false; +110 ¦ } +111 ¦ string word = next_word(in); +112 ¦ if (word.empty()) { +113 ¦ ¦ assert(!has_data(in)); +114 ¦ ¦ raise << "incomplete recipe at end of file (2)\n" << end(); +115 ¦ ¦ return false; +116 ¦ } +117 ¦ words.push_back(word); +118 ¦ skip_whitespace_but_not_newline(in); 119 } 120 skip_whitespace_and_comments(in); 121 if (SIZE(words) == 1 && words.at(0) == "]") -122 return false; // end of recipe +122 ¦ return false; // end of recipe 123 124 if (SIZE(words) == 1 && is_label_word(words.at(0))) { -125 curr->is_label = true; -126 curr->label = words.at(0); -127 trace(9993, "parse") << "label: " << curr->label << end(); -128 if (!has_data(in)) { -129 raise << "incomplete recipe at end of file (3)\n" << end(); -130 return false; -131 } -132 return true; +125 ¦ curr->is_label = true; +126 ¦ curr->label = words.at(0); +127 ¦ trace(9993, "parse") << "label: " << curr->label << end(); +128 ¦ if (!has_data(in)) { +129 ¦ ¦ raise << "incomplete recipe at end of file (3)\n" << end(); +130 ¦ ¦ return false; +131 ¦ } +132 ¦ return true; 133 } 134 135 vector<string>::iterator p = words.begin(); 136 if (find(words.begin(), words.end(), "<-") != words.end()) { -137 for (; *p != "<-"; ++p) -138 curr->products.push_back(reagent(*p)); -139 ++p; // skip <- +137 ¦ for (; *p != "<-"; ++p) +138 ¦ ¦ curr->products.push_back(reagent(*p)); +139 ¦ ++p; // skip <- 140 } 141 142 if (p == words.end()) { -143 raise << "instruction prematurely ended with '<-'\n" << end(); -144 return false; +143 ¦ raise << "instruction prematurely ended with '<-'\n" << end(); +144 ¦ return false; 145 } 146 curr->name = *p; ++p; 147 // curr->operation will be set at transform time 148 149 for (; p != words.end(); ++p) -150 curr->ingredients.push_back(reagent(*p)); +150 ¦ curr->ingredients.push_back(reagent(*p)); 151 152 trace(9993, "parse") << "instruction: " << curr->name << end(); 153 trace(9993, "parse") << " number of ingredients: " << SIZE(curr->ingredients) << end(); 154 for (vector<reagent>::iterator p = curr->ingredients.begin(); p != curr->ingredients.end(); ++p) -155 trace(9993, "parse") << " ingredient: " << to_string(*p) << end(); +155 ¦ trace(9993, "parse") << " ingredient: " << to_string(*p) << end(); 156 for (vector<reagent>::iterator p = curr->products.begin(); p != curr->products.end(); ++p) -157 trace(9993, "parse") << " product: " << to_string(*p) << end(); +157 ¦ trace(9993, "parse") << " product: " << to_string(*p) << end(); 158 if (!has_data(in)) { -159 raise << "9: unbalanced '[' for recipe\n" << end(); -160 return false; +159 ¦ raise << "9: unbalanced '[' for recipe\n" << end(); +160 ¦ return false; 161 } 162 // End next_instruction(curr) 163 return true; @@ -234,7 +235,7 @@ if ('onhashchange' in window) { 172 skip_whitespace_and_comments_but_not_newline(in); 173 string result = out.str(); 174 if (result != "[" && ends_with(result, '[')) -175 raise << "insert a space before '[' in '" << result << "'\n" << end(); +175 ¦ raise << "insert a space before '[' in '" << result << "'\n" << end(); 176 return result; 177 } 178 @@ -255,45 +256,45 @@ if ('onhashchange' in window) { 193 void slurp_word(istream& in, ostream& out) { 194 char c; 195 if (has_data(in) && Terminators.find(in.peek()) != string::npos) { -196 in >> c; -197 out << c; -198 return; +196 ¦ in >> c; +197 ¦ out << c; +198 ¦ return; 199 } 200 while (in >> c) { -201 if (isspace(c) || Terminators.find(c) != string::npos || Ignore.find(c) != string::npos) { -202 in.putback(c); -203 break; -204 } -205 out << c; +201 ¦ if (isspace(c) || Terminators.find(c) != string::npos || Ignore.find(c) != string::npos) { +202 ¦ ¦ in.putback(c); +203 ¦ ¦ break; +204 ¦ } +205 ¦ out << c; 206 } 207 } 208 209 void skip_whitespace_and_comments(istream& in) { 210 while (true) { -211 if (!has_data(in)) break; -212 if (isspace(in.peek())) in.get(); -213 else if (Ignore.find(in.peek()) != string::npos) in.get(); -214 else if (in.peek() == '#') skip_comment(in); -215 else break; +211 ¦ if (!has_data(in)) break; +212 ¦ if (isspace(in.peek())) in.get(); +213 ¦ else if (Ignore.find(in.peek()) != string::npos) in.get(); +214 ¦ else if (in.peek() == '#') skip_comment(in); +215 ¦ else break; 216 } 217 } 218 219 // confusing; move to the next line only to skip a comment, but never otherwise 220 void skip_whitespace_and_comments_but_not_newline(istream& in) { 221 while (true) { -222 if (!has_data(in)) break; -223 if (in.peek() == '\n') break; -224 if (isspace(in.peek())) in.get(); -225 else if (Ignore.find(in.peek()) != string::npos) in.get(); -226 else if (in.peek() == '#') skip_comment(in); -227 else break; +222 ¦ if (!has_data(in)) break; +223 ¦ if (in.peek() == '\n') break; +224 ¦ if (isspace(in.peek())) in.get(); +225 ¦ else if (Ignore.find(in.peek()) != string::npos) in.get(); +226 ¦ else if (in.peek() == '#') skip_comment(in); +227 ¦ else break; 228 } 229 } 230 231 void skip_comment(istream& in) { 232 if (has_data(in) && in.peek() == '#') { -233 in.get(); -234 while (has_data(in) && in.peek() != '\n') in.get(); +233 ¦ in.get(); +234 ¦ while (has_data(in) && in.peek() != '\n') in.get(); 235 } 236 } 237 @@ -416,9 +417,9 @@ if ('onhashchange' in window) { 354 :(code) 355 void test_parse_comment_terminated_by_eof() { 356 load("recipe main [\n" -357 " a:number <- copy 34\n" -358 "]\n" -359 "# abc"); // no newline after comment +357 ¦ ¦ ¦" a:number <- copy 34\n" +358 ¦ ¦ ¦"]\n" +359 ¦ ¦ ¦"# abc"); // no newline after comment 360 cerr << "."; // termination = success 361 } 362 @@ -468,7 +469,7 @@ if ('onhashchange' in window) { 406 cerr << '^'; 407 char c; 408 while (in >> c) -409 cerr << c; +409 ¦ cerr << c; 410 cerr << "$\n"; 411 exit(0); 412 } -- cgit 1.4.1-2-gfad0