From 7232de7061e8c370ad6cf76988489d78e269f8b9 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 20 Feb 2015 20:32:05 -0800 Subject: 802 - mu comments Comments at end of line are still hacky; we just rely on the fact that excess ingredients do no harm. We'll need to be smarter when we get our first vararg recipe. --- cpp/011load | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'cpp/011load') diff --git a/cpp/011load b/cpp/011load index f2855e5f..0193eeac 100644 --- a/cpp/011load +++ b/cpp/011load @@ -13,6 +13,7 @@ int add_recipe(string form) { istringstream in(form); in >> std::noskipws; + skip_comments_and_newlines(in); string _recipe = next_word(in); if (_recipe != "recipe") raise << "top-level forms must be of the form 'recipe _name_ [ _instruction_ ... ]'\n"; @@ -25,7 +26,7 @@ int add_recipe(string form) { if (next_word(in) != "[") raise << "recipe body must begin with '['\n"; - skip_newlines(in); + skip_comments_and_newlines(in); instruction curr; while (next_instruction(in, &curr)) { @@ -38,7 +39,7 @@ bool next_instruction(istream& in, instruction* curr) { curr->clear(); if (in.eof()) return false; skip_whitespace(in); if (in.eof()) return false; - skip_newlines(in); if (in.eof()) return false; + skip_comments_and_newlines(in); if (in.eof()) return false; vector words; while (in.peek() != '\n') { @@ -47,7 +48,7 @@ bool next_instruction(istream& in, instruction* curr) { words.push_back(word); skip_whitespace(in); if (in.eof()) return false; } - skip_newlines(in); if (in.eof()) return false; + skip_comments_and_newlines(in); if (in.eof()) return false; if (words.size() == 1 && *(words[0].end()-1) == ':') { curr->is_label = true; @@ -112,9 +113,14 @@ void skip_whitespace(istream& in) { } } -void skip_newlines(istream& in) { - while (in.peek() == '\n') +void skip_comments_and_newlines(istream& in) { + while (in.peek() == '\n' || in.peek() == '#') { + if (in.peek() == '#') { + in.get(); + while (in.peek() != '\n') in.get(); + } in.get(); + } } void skip_comma(istream& in) { -- cgit 1.4.1-2-gfad0