diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-03-14 17:55:22 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-03-14 18:05:41 -0700 |
commit | 9429b278821475d9d9cfa14ba47e805d20b33479 (patch) | |
tree | ae883b872df370d74cb0d891e82b3929a957f127 /cpp | |
parent | d241c9c41cdf2c1d0aa01d9ddb00e110ebaded97 (diff) | |
download | mu-9429b278821475d9d9cfa14ba47e805d20b33479.tar.gz |
912 - tangle: another directive 'following' for nested patterns
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/tangle/030tangle.cc | 38 | ||||
-rw-r--r-- | cpp/tangle/030tangle.test.cc | 7 |
2 files changed, 39 insertions, 6 deletions
diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc index 2d1bc191..cdf28d91 100644 --- a/cpp/tangle/030tangle.cc +++ b/cpp/tangle/030tangle.cc @@ -70,13 +70,39 @@ void process_next_hunk(istream& in, const string& directive, list<string>& out) RAISE << "No target for " << cmd << " directive.\n" << die(); return; } - list<string>::iterator target = find_substr(out, pat); - if (target == out.end()) { - RAISE << "Couldn't find target " << pat << '\n' << die(); - return; - } - if (next_tangle_token(directive_stream) == "then") { + list<string>::iterator target = out.begin(); + string next_token = next_tangle_token(directive_stream); + if (next_token == "") { + target = find_substr(out, pat); + if (target == out.end()) { + RAISE << "Couldn't find target " << pat << '\n' << die(); + return; + } + } + else if (next_token == "following") { + string pat2 = next_tangle_token(directive_stream); + if (pat2 == "") { + RAISE << "No target for 'following' in " << directive << ".\n" << die(); + return; + } + target = find_substr(out, pat2); + if (target == out.end()) { + RAISE << "Couldn't find target " << pat2 << die(); + return; + } + target = find_substr(out, target, pat); + if (target == out.end()) { + RAISE << "Couldn't find target " << pat << '\n' << die(); + return; + } + } + else if (next_token == "then") { + target = find_substr(out, pat); + if (target == out.end()) { + RAISE << "Couldn't find target " << pat << '\n' << die(); + return; + } string pat2 = next_tangle_token(directive_stream); if (pat2 == "") { RAISE << "No target for then directive following " << cmd << ".\n" << die(); diff --git a/cpp/tangle/030tangle.test.cc b/cpp/tangle/030tangle.test.cc index cf42d71c..eb468894 100644 --- a/cpp/tangle/030tangle.test.cc +++ b/cpp/tangle/030tangle.test.cc @@ -83,6 +83,13 @@ void test_tangle_nested_patterns() { CHECK_TRACE_CONTENTS("tangle", "acbced"); } +void test_tangle_nested_patterns2() { + istringstream in("a\nc\nb\nc\nd\n:(after \"c\" following \"b\")\ne"); + list<string> dummy; + tangle(in, dummy); + CHECK_TRACE_CONTENTS("tangle", "acbced"); +} + // todo: include line numbers in tangle errors |