Ejemplo n.º 1
0
    inline bool st_search(StateParser & stparser, const char * s)
    {
        if ( stparser.empty()) {
            return false;
        }

        StatesValue stval(stparser.states(), stparser.nb_capture());

// #ifdef DISPLAY_TRACE
//         display_states(stval, stparser.root());
// #endif

        st_step_range_list_t lst;
        st_step_range_list_t l1;
        add_first(lst, l1, stparser.root());
        if (l1.empty() && lst.empty()) {
            return false;
        }
        utf8_consumer consumer(s);
        st_step_range_list_t l2;
        bool res = false;
        unsigned count = 1;
        while (consumer.valid()) {
#ifdef DISPLAY_TRACE
            std::cout << "\033[01;31mc: '" << utf8_char(consumer.getc()) << "'\033[0m\n";
#endif
            for (st_step_range_iterator_t first = lst.begin(), last = lst.end(); first != last; ++first) {
                if (stval.get_num_at(first->first) != count) {
                    l1.push_back(*first);
                }
            }
            if (l1.empty()) {
                return false;
            }
            l2.clear();
            if ((res = st_step(l1, l2, stval, consumer.bumpc(), consumer, ++count))) {
                break ;
            }
            l1.swap(l2);
        }
        if (res) {
            return true;
        }
        if (consumer.valid()) {
            return false;
        }
        for (st_step_range_iterator_t first = l1.begin(), last = l1.end(); first != last; ++first) {
            if (first->first->type == LAST) {
                return true;
            }
        }
        return false;
    }
    inline bool st_exact_search(StateParser & stparser, const char * s)
    {
        if ( stparser.empty() ) {
            return false;
        }

        StatesValue stval(stparser.states(), stparser.nb_capture());

// #ifdef DISPLAY_TRACE
//         display_states(stval, stparser.root());
// #endif

        st_step_range_list_t l1;
        add_first(l1, l1, stparser.root());
        if (l1.empty()) {
            return false;
        }
        utf8_consumer consumer(s);
        st_step_range_list_t l2;
        bool res = false;
        unsigned count = 1;
        while (consumer.valid() && !(res = st_exact_step(l1, l2, stval, consumer.bumpc(), consumer, ++count))) {
#ifdef DISPLAY_TRACE
            std::cout << "\033[01;31mc: '" << utf8_char(consumer.getc()) << "'\033[0m\n";
#endif
            if (l2.empty()) {
                return false;
            }
            l1.swap(l2);
            l2.clear();
        }

        if (consumer.valid()) {
            return false;
        }
        if (res) {
            return true;
        }
        return false;
    }