diff options
Diffstat (limited to 'tools/bookmaker/bookmaker.cpp')
-rw-r--r-- | tools/bookmaker/bookmaker.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/tools/bookmaker/bookmaker.cpp b/tools/bookmaker/bookmaker.cpp index ffd3012e24..1b8e76ee33 100644 --- a/tools/bookmaker/bookmaker.cpp +++ b/tools/bookmaker/bookmaker.cpp @@ -703,6 +703,55 @@ Definition* BmhParser::findExample(string name) const { return nullptr; } +static bool check_example_hashes(Definition* def) { + if (MarkType::kExample == def->fMarkType) { + if (def->fHash.length()) { + return true; + } + for (auto child : def->fChildren) { + if (MarkType::kPlatform == child->fMarkType) { + if (string::npos != string(child->fContentStart, child->length()).find("!fiddle")) { + return true; + } + } + } + return def->reportError<bool>("missing hash"); + } + for (auto& child : def->fChildren) { + if (!check_example_hashes(child)) { + return false; + } + } + return true; +} + +bool BmhParser::checkExampleHashes() const { + for (const auto& topic : fTopicMap) { + if (!topic.second->fParent && !check_example_hashes(topic.second)) { + return false; + } + } + return true; +} + +static void reset_example_hashes(Definition* def) { + if (MarkType::kExample == def->fMarkType) { + def->fHash.clear(); + return; + } + for (auto& child : def->fChildren) { + reset_example_hashes(child); + } +} + +void BmhParser::resetExampleHashes() { + for (const auto& topic : fTopicMap) { + if (!topic.second->fParent) { + reset_example_hashes(topic.second); + } + } +} + static void find_examples(const Definition& def, vector<string>* exampleNames) { if (MarkType::kExample == def.fMarkType) { exampleNames->push_back(def.fFiddle); @@ -2640,7 +2689,7 @@ int main(int argc, char** const argv) { } if (!done && !FLAGS_fiddle.isEmpty() && FLAGS_examples.isEmpty()) { FiddleParser fparser(&bmhParser); - if (!fparser.parseFile(FLAGS_fiddle[0], ".txt", ParserCommon::OneFile::kNo)) { + if (!fparser.parseFromFile(FLAGS_fiddle[0])) { return -1; } } |