示例#1
0
void Tok::Unresolve(Matcher const &matcher)
{
    int i;
    TokIdNode *nd;

    for(i = node.size(); i--;)
    {
        for(nd = node[i]; nd->v_prev != 0 && !matcher.Match(nd); nd = nd->v_prev)
        {
            unres[i + 1].push_front(nd->id[0]);
        }
    }
}
示例#2
0
TokArr Tok::GetDescendants(Matcher const &matcher) const
{
    TokIdNode *nd[2];
    TokArr rv;

    for(nd[0] = TokIdNode::GetLeaf(nd[1] = Node()); nd[0] != nd[1]; nd[0] = TokIdNode::GetNext(nd[0], nd[1]))
    {
        if(matcher.Match(nd[0]))
        {
            rv.push_back(nd[0]);
        }
    }

    return rv;
}
示例#3
0
std::vector< std::pair< TokIdNode *, int > > TokIdNode::AmbigResolve(
    TokIdNode const *node,
    std::deque< TokId >::const_iterator arr,
    int len,
    Matcher const &matcher,
    TokIdNode const *context,
    TokIdNode const *subroot)
{
    int i;
    Map::const_iterator it, itEnd;
    std::vector< std::pair< TokIdNode *, int > > rv[2];
    TokIdNode const *nd;

    if(len == 0)
    {
        if(node && node->IsInContext(context) && matcher.Match(node))
        {
            rv[0].push_back(std::make_pair((TokIdNode *)node, 0));
        }
        return rv[0];
    }

    if(node && !context->IsInContext(node) && !node->IsInContext(context))
    {
        return rv[0];
    }

    if(!context->IsInContext(subroot))
    {
        PNL_THROW(pnl::CBadArg, "context must lie in subtree rooted at subroot");
    }

    if(node == 0 && subroot->Match(arr[0]))
    {
        rv[1] = AmbigResolve(subroot, arr + 1, len - 1, matcher, context, subroot);
        for(i = rv[1].size(); i--;)
        {
            rv[0].push_back(std::make_pair(rv[1][i].first, rv[1][i].second + 1));
        }
    }

    nd = node ? node : subroot;
    it = nd->desc.find(arr[0]);
    if(it != nd->desc.end())
    {
	for(itEnd = nd->desc.upper_bound(arr[0]); it != itEnd; ++it)
	{
	    rv[1] = AmbigResolve(it->second, arr + 1, len - 1, matcher, context, subroot);
	    for(i = rv[1].size(); i--;)
	    {
		rv[0].push_back(std::make_pair(rv[1][i].first, rv[1][i].second + 1));
	    }
	}
    }

    if(rv[0].empty())
    {
        rv[0].push_back(std::make_pair((TokIdNode *)node, 0));
    }
    return rv[0];
}