Store the same tree for ApplyBlocks too.
This commit is contained in:
parent
2fd4daf52c
commit
41bb315b02
2 changed files with 30 additions and 20 deletions
|
@ -36,12 +36,6 @@ namespace duck { namespace sl {
|
|||
namespace {
|
||||
struct EntryNode;
|
||||
|
||||
struct ApplyEntry {
|
||||
const SourceInfo* apply_to;
|
||||
const std::vector<StructItem>* content;
|
||||
const std::string* mustache_name;
|
||||
};
|
||||
|
||||
struct MustacheEntry {
|
||||
std::string text;
|
||||
mstch::map context;
|
||||
|
@ -49,7 +43,7 @@ namespace duck { namespace sl {
|
|||
|
||||
using EntryNodeList = std::vector<std::pair<
|
||||
const SourceInfo*,
|
||||
std::vector<EntryNode>
|
||||
EntryNode
|
||||
>>;
|
||||
using MustacheEntryMap = std::map<std::string, MustacheEntry>;
|
||||
|
||||
|
@ -66,6 +60,21 @@ namespace duck { namespace sl {
|
|||
std::vector<const XPathElement*> xpaths;
|
||||
};
|
||||
|
||||
struct ApplyEntry {
|
||||
ApplyEntry (const SourceInfo* parAppTo, std::string_view parMstchName) :
|
||||
apply_to(parAppTo),
|
||||
content(""),
|
||||
mustache_name(parMstchName)
|
||||
{
|
||||
}
|
||||
ApplyEntry (ApplyEntry&&) = default;
|
||||
ApplyEntry& operator=(ApplyEntry&&) = default;
|
||||
|
||||
const SourceInfo* apply_to;
|
||||
EntryNode content;
|
||||
std::string_view mustache_name;
|
||||
};
|
||||
|
||||
class StructItemExtractor : public boost::static_visitor<> {
|
||||
public:
|
||||
explicit StructItemExtractor (EntryNode& parRoot) :
|
||||
|
@ -89,6 +98,16 @@ namespace duck { namespace sl {
|
|||
EntryNode& m_root;
|
||||
};
|
||||
|
||||
void store_entry_subtree (
|
||||
const std::vector<StructItem>& parXPaths,
|
||||
EntryNode& parCurrList
|
||||
) {
|
||||
for (auto& itm : parXPaths) {
|
||||
StructItemExtractor extractor(parCurrList);
|
||||
boost::apply_visitor(extractor, itm);
|
||||
}
|
||||
}
|
||||
|
||||
class DictBuilder : public boost::static_visitor<> {
|
||||
public:
|
||||
explicit DictBuilder (HtmlPoolBaseSP parHtmlPool) :
|
||||
|
@ -109,26 +128,18 @@ namespace duck { namespace sl {
|
|||
#endif
|
||||
m_global_entries.emplace_back(std::make_pair(
|
||||
&parVal.source,
|
||||
std::vector<EntryNode>()
|
||||
EntryNode("")
|
||||
));
|
||||
auto& curr_list = m_global_entries.back().second;
|
||||
|
||||
for (auto& itm : parVal.xpaths) {
|
||||
curr_list.emplace_back("");
|
||||
StructItemExtractor extractor(curr_list.back());
|
||||
boost::apply_visitor(extractor, itm);
|
||||
}
|
||||
store_entry_subtree(parVal.xpaths, m_global_entries.back().second);
|
||||
}
|
||||
|
||||
void operator() (const ApplyBlock& parVal) {
|
||||
#if defined(APPLY_VERBOSE)
|
||||
std::cout << parVal << '\n';
|
||||
#endif
|
||||
m_apply_entries.push_back(ApplyEntry {
|
||||
&parVal.source,
|
||||
&parVal.xpaths,
|
||||
&parVal.mustache_model
|
||||
});
|
||||
m_apply_entries.emplace_back(&parVal.source, parVal.mustache_model);
|
||||
store_entry_subtree(parVal.xpaths, m_apply_entries.back().content);
|
||||
}
|
||||
|
||||
void operator() (const MustacheBlock& parVal) {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
namespace duck { namespace sl {
|
||||
std::vector<ScrapNode> parse ( const std::string& parData );
|
||||
//std::vector<element_def> get_xpath_definitions ( const ScrapNode& parAST );
|
||||
}} //namespace duck::sl
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue