+ // Track child documents
+ for (size_t i = 0; i < token.length(); ++i) {
+ if (token[i] == '(') {
+ ++pnest;
+ size_t j = token.find('(', i + 1);
+ size_t len = j == string::npos
+ ? token.substr(i + 1).length()
+ : j - i - 1;
+ if (regex_match(token.substr(i + 1, len),
+ sub, child_file)) {
+ string const name = sub.str(1);
+ child.push(make_pair(name, pnest));
+ i += len;
+ }
+ } else if (token[i] == ')') {
+ if (!child.empty()
+ && child.top().second == pnest)
+ child.pop();
+ --pnest;
+ }
+ }
+ child_name = child.empty() ? empty_string() : child.top().first;
+