diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/002main.cc | 30 | ||||
-rw-r--r-- | cpp/002main.test.cc | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/cpp/002main.cc b/cpp/002main.cc index c2baea50..cb0ed411 100644 --- a/cpp/002main.cc +++ b/cpp/002main.cc @@ -142,6 +142,36 @@ void setup_types() { } void compile(string form) { + istringstream in(form); + in >> std::noskipws; + if (next_word(in) != "recipe") + RAISE << "top-level forms must be of the form 'recipe _name_ [ _instruction_ ... ]'"; +} + +string next_word(istream& in) { + ostringstream out; + skip_whitespace(in); + slurp_word(in, out); +//? cout << out.str() << '\n'; //? 1 + return out.str(); +} + +void slurp_word(istream& in, ostream& out) { + char c; + while (in >> c) { +//? cout << c << '\n'; //? 1 + if (isspace(c)) { +//? cout << " space\n"; //? 1 + in.putback(c); + break; + } + out << c; + } +} + +void skip_whitespace(istream& in) { + while (isspace(in.peek()) && in.peek() != '\n') + in.get(); } diff --git a/cpp/002main.test.cc b/cpp/002main.test.cc index b622828b..1f77ab39 100644 --- a/cpp/002main.test.cc +++ b/cpp/002main.test.cc @@ -1,5 +1,5 @@ void test_literal() { - compile("function main [\n" + compile("recipe main [\n" " 1:integer <- copy 23:literal\n" "]\n"); run("main"); |