1
2
3
4
5
6 :(scenarios load)
7 :(scenario first_recipe)
8 def main [
9 1:number <- copy 23
10 ]
11 +parse: instruction: copy
12 +parse: ingredient: {23: "literal"}
13 +parse: product: {1: "number"}
14
15 :(code)
16 vector<recipe_ordinal> load(string form) {
17 istringstream in(form);
18 in >> std::noskipws;
19 return load(in);
20 }
21
22 vector<recipe_ordinal> load(istream& in) {
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
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
45 else {
46 raise << "unknown top-level command: " << command << '\n' << end();
47 }
48 }
49 return result;
50 }
51
52
53 int slurp_recipe(istream& in) {
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;
60 }
61
62 skip_whitespace_but_not_newline(in);
63
64 if (result.name.empty())
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);
69 result.ordinal = get(Recipe_ordinal, result.name);
70 ++Next_recipe_ordinal;
71 if (Recipe.find(get(Recipe_ordinal, result.name)) != Recipe.end()) {
72 trace(9991, &<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module ranger.__main__</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="ranger.html"><font color="#ffffff">ranger</font></a>.__main__</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/ranger/ranger/__main__.py">/home/hut/ranger/ranger/__main__.py</a></font></td></tr></table>
<p><tt># coding=utf-8<br>
#<br>
# Copyright (C) 2009, 2010 Roman Zimbelmann <romanz@lavabit.com><br>
#<br>
# This program is free software: you can redistribute it and/or modify<br>
# it under the terms of the GNU General Public License as published by<br>
# the Free Software Foundation, either version 3 of the License, or<br>
# (at your option) any later version.<br>
#<br>
# This program is distributed in the hope that it will be useful,<br>
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
# GNU General Public License for more details.<br>
#<br>
# You should have received a copy of the GNU General Public License<br>
# along with this program. If not, see <<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-main"><strong>main</strong></a>()</dt><dd><tt>initialize objects and run the filemanager</tt></dd></dl>
<dl><dt><a name="-parse_arguments"><strong>parse_arguments</strong></a>()</dt><dd><tt>Parse the program arguments</tt></dd></dl>
</td></tr></table>
</body></html>