Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

libs/spirit/classic/example/fundamental/distinct/distinct_parser.cpp

Boost , ,

Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

libs/spirit/classic/example/fundamental/distinct/distinct_parser.cpp

/*=============================================================================
    Copyright (c) 2003 Vaclav Vesely
    http://spirit.sourceforge.net/
    Use, modification and distribution is subject to the Boost Software
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include <boost/assert.hpp>
#include <iostream>
#include <boost/cstdlib.hpp>
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_distinct.hpp>
using namespace std;
using namespace boost;
using namespace BOOST_SPIRIT_CLASSIC_NS;
// keyword_p for C++
// (for basic usage instead of std_p)
const distinct_parser<> keyword_p("0-9a-zA-Z_");
// keyword_d for C++
// (for mor intricate usage, for example together with symbol tables)
const distinct_directive<> keyword_d("0-9a-zA-Z_");
struct my_grammar: public grammar<my_grammar>
{
    template <typename ScannerT>
    struct definition
    {
        typedef rule<ScannerT> rule_t;
        definition(my_grammar const& self)
        {
            top
                =
                    keyword_p("declare") // use keyword_p instead of std_p
                >>  !ch_p(':')
                >>  keyword_d[str_p("ident")] // use keyword_d
                ;
        }
        rule_t top;
        rule_t const& start() const
        {
            return top;
        }
    };
};
int main()
{
    my_grammar gram;
    parse_info<> info;
    info = parse("declare ident", gram, space_p);
    BOOST_ASSERT(info.full); // valid input
    info = parse("declare: ident", gram, space_p);
    BOOST_ASSERT(info.full); // valid input
    info = parse("declareident", gram, space_p);
    BOOST_ASSERT(!info.hit); // invalid input
    return exit_success;
}

Статья libs/spirit/classic/example/fundamental/distinct/distinct_parser.cpp раздела может быть полезна для разработчиков на c++ и boost.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-20 09:09:35/0.0056040287017822/0