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 {
|
namespace {
|
||||||
struct EntryNode;
|
struct EntryNode;
|
||||||
|
|
||||||
struct ApplyEntry {
|
|
||||||
const SourceInfo* apply_to;
|
|
||||||
const std::vector<StructItem>* content;
|
|
||||||
const std::string* mustache_name;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MustacheEntry {
|
struct MustacheEntry {
|
||||||
std::string text;
|
std::string text;
|
||||||
mstch::map context;
|
mstch::map context;
|
||||||
|
@ -49,7 +43,7 @@ namespace duck { namespace sl {
|
||||||
|
|
||||||
using EntryNodeList = std::vector<std::pair<
|
using EntryNodeList = std::vector<std::pair<
|
||||||
const SourceInfo*,
|
const SourceInfo*,
|
||||||
std::vector<EntryNode>
|
EntryNode
|
||||||
>>;
|
>>;
|
||||||
using MustacheEntryMap = std::map<std::string, MustacheEntry>;
|
using MustacheEntryMap = std::map<std::string, MustacheEntry>;
|
||||||
|
|
||||||
|
@ -66,6 +60,21 @@ namespace duck { namespace sl {
|
||||||
std::vector<const XPathElement*> xpaths;
|
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<> {
|
class StructItemExtractor : public boost::static_visitor<> {
|
||||||
public:
|
public:
|
||||||
explicit StructItemExtractor (EntryNode& parRoot) :
|
explicit StructItemExtractor (EntryNode& parRoot) :
|
||||||
|
@ -89,6 +98,16 @@ namespace duck { namespace sl {
|
||||||
EntryNode& m_root;
|
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<> {
|
class DictBuilder : public boost::static_visitor<> {
|
||||||
public:
|
public:
|
||||||
explicit DictBuilder (HtmlPoolBaseSP parHtmlPool) :
|
explicit DictBuilder (HtmlPoolBaseSP parHtmlPool) :
|
||||||
|
@ -109,26 +128,18 @@ namespace duck { namespace sl {
|
||||||
#endif
|
#endif
|
||||||
m_global_entries.emplace_back(std::make_pair(
|
m_global_entries.emplace_back(std::make_pair(
|
||||||
&parVal.source,
|
&parVal.source,
|
||||||
std::vector<EntryNode>()
|
EntryNode("")
|
||||||
));
|
));
|
||||||
auto& curr_list = m_global_entries.back().second;
|
|
||||||
|
|
||||||
for (auto& itm : parVal.xpaths) {
|
store_entry_subtree(parVal.xpaths, m_global_entries.back().second);
|
||||||
curr_list.emplace_back("");
|
|
||||||
StructItemExtractor extractor(curr_list.back());
|
|
||||||
boost::apply_visitor(extractor, itm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator() (const ApplyBlock& parVal) {
|
void operator() (const ApplyBlock& parVal) {
|
||||||
#if defined(APPLY_VERBOSE)
|
#if defined(APPLY_VERBOSE)
|
||||||
std::cout << parVal << '\n';
|
std::cout << parVal << '\n';
|
||||||
#endif
|
#endif
|
||||||
m_apply_entries.push_back(ApplyEntry {
|
m_apply_entries.emplace_back(&parVal.source, parVal.mustache_model);
|
||||||
&parVal.source,
|
store_entry_subtree(parVal.xpaths, m_apply_entries.back().content);
|
||||||
&parVal.xpaths,
|
|
||||||
&parVal.mustache_model
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator() (const MustacheBlock& parVal) {
|
void operator() (const MustacheBlock& parVal) {
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
namespace duck { namespace sl {
|
namespace duck { namespace sl {
|
||||||
std::vector<ScrapNode> parse ( const std::string& parData );
|
std::vector<ScrapNode> parse ( const std::string& parData );
|
||||||
//std::vector<element_def> get_xpath_definitions ( const ScrapNode& parAST );
|
|
||||||
}} //namespace duck::sl
|
}} //namespace duck::sl
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue