TLCIter Reduce(ValueNode& node, TLCIter b, TLCIter e) { while(b != e && *b != ")") if(*b == "(") { auto nd(MakeNode(to_string(node.GetSize()))); auto res(Reduce(nd, ++b, e)); if(res == e || *res != ")") throw LoggedEvent("Redundant '(' found.", Alert); node += std::move(nd); b = ++res; } else node += {0, to_string(node.GetSize()), *b++}; return b; }
ValueNode TransformNPLA1(const ValueNode& node, std::function<NodeMapper> mapper) { auto s(node.GetSize()); if(s == 0) return {0, "", node ? Deliteralize(Access<string>(node)) : string()}; auto i(node.begin()); if(s == 1) return TransformNPLA1(*i, mapper); const auto& name(ParseNPLANodeString(*i)); if(!name.empty()) yunseq(++i, --s); if(s == 1) { auto&& n(TransformNPLA1(*i, mapper)); if(n.GetName().empty()) return {0, name, std::move(n.Value)}; return {ValueNode::Container{std::move(n)}, name}; } auto p_node_con(make_unique<ValueNode::Container>()); std::for_each(i, node.end(), [&](const ValueNode& nd){ auto&& n(mapper ? mapper(nd) : TransformNPLA1(nd, mapper)); p_node_con->insert(n.GetName().empty() ? ValueNode(0, '$' + std::to_string(p_node_con->size()), std::move(n.Value)) : std::move(n)); }); return {std::move(p_node_con), name}; }