From 1f7e3c056ce0ea71e1337579b24e8fd1ad26abac Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 2 Dec 2015 17:11:58 -0800 Subject: 2614 - still fixing bugs with missing '[' When skipping past some text (usually whitespace, but also commas and comments) I need to always be aware of whether it's ok to switch to the next line or not. --- 056recipe_header.cc | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to '056recipe_header.cc') diff --git a/056recipe_header.cc b/056recipe_header.cc index f0d448b2..2ca02af7 100644 --- a/056recipe_header.cc +++ b/056recipe_header.cc @@ -23,7 +23,6 @@ vector products; has_header = false; :(before "End recipe Refinements") -skip_whitespace(in); if (in.peek() != '[') { trace(9999, "parse") << "recipe has a header; parsing" << end(); load_recipe_header(in, result); @@ -37,17 +36,28 @@ void load_recipe_header(istream& in, recipe& result) { if (s == "->") break; result.ingredients.push_back(reagent(s)); trace(9999, "parse") << "header ingredient: " << result.ingredients.back().original_string << end(); - skip_whitespace_and_comments(in); + skip_whitespace_and_comments_but_not_newline(in); } while (has_data(in) && in.peek() != '[' && in.peek() != '\n') { string s = next_word(in); result.products.push_back(reagent(s)); trace(9999, "parse") << "header product: " << result.products.back().original_string << end(); - skip_whitespace_and_comments(in); + skip_whitespace_and_comments_but_not_newline(in); } // End Load Recipe Header(result) } +void skip_whitespace_and_comments_but_not_newline(istream& in) { + while (true) { + if (!has_data(in)) break; + if (in.peek() == '\n') break; + if (isspace(in.peek())) in.get(); + else if (Ignore.find(in.peek()) != string::npos) in.get(); + else if (in.peek() == '#') skip_comment(in); + else break; + } +} + :(scenario recipe_handles_stray_comma) recipe main [ 1:number/raw <- add2 3, 5 @@ -78,6 +88,17 @@ recipe main ] +error: recipe body must begin with '[' +:(scenario recipe_handles_missing_bracket_2) +% Hide_errors = true; +recipe main + local-scope + { + } +] +# doesn't overflow line when reading header +-parse: header ingredient: local-scope ++error: recipe body must begin with '[' + :(after "Begin debug_string(recipe x)") out << "ingredients:\n"; for (long long int i = 0; i < SIZE(x.ingredients); ++i) -- cgit 1.4.1-2-gfad0