diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-12-02 18:17:59 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-12-02 18:17:59 -0800 |
commit | 3c93ddcbaa5edd4e2c0404c3ef0b149b2a33a9f6 (patch) | |
tree | 96b63d6eb8bfab181379e531941b14c89a878580 /011load.cc | |
parent | 1f7e3c056ce0ea71e1337579b24e8fd1ad26abac (diff) | |
download | mu-3c93ddcbaa5edd4e2c0404c3ef0b149b2a33a9f6.tar.gz |
2615
We don't actually need skip_whitespace_AND_comments_BUT_NOT_newline anywhere except next_word(). Perhaps what I should really do is split the definition of next_word() into two variants..
Diffstat (limited to '011load.cc')
-rw-r--r-- | 011load.cc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/011load.cc b/011load.cc index 14811e38..e5122edb 100644 --- a/011load.cc +++ b/011load.cc @@ -43,7 +43,7 @@ vector<recipe_ordinal> load(istream& in) { long long int slurp_recipe(istream& in) { recipe result; result.name = next_word(in); - skip_whitespace_and_comments_but_not_newline(in); + skip_whitespace_but_not_newline(in); // End recipe Refinements if (result.name.empty()) raise_error << "empty result.name\n" << end(); @@ -67,10 +67,10 @@ long long int slurp_recipe(istream& in) { void slurp_body(istream& in, recipe& result) { in >> std::noskipws; - skip_whitespace_and_comments(in); + skip_whitespace_but_not_newline(in); if (in.get() != '[') raise_error << "recipe body must begin with '['\n" << end(); - skip_whitespace_and_comments(in); + skip_whitespace_and_comments(in); // permit trailing comment after '[' instruction curr; while (next_instruction(in, &curr)) { // End Rewrite Instruction(curr, recipe result) @@ -150,7 +150,7 @@ bool next_instruction(istream& in, instruction* curr) { } string next_word(istream& in) { - skip_whitespace_and_comments_but_not_newline(in); + skip_whitespace_but_not_newline(in); // End next_word Special-cases ostringstream out; slurp_word(in, out); @@ -188,6 +188,18 @@ void skip_whitespace_and_comments(istream& in) { } } +// confusing; move to the next line only to skip a comment, but never otherwise +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; + } +} + void skip_comment(istream& in) { if (has_data(in) && in.peek() == '#') { in.get(); |