[Spirit Qi %] (x%y) not semantically equivalent to (x >> *(y >> x))

Frank Hein <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <OF9AB6BCBF.6A515C09-ONC1257FBE.0060CDB1-C1257FBE.0061E33E@maxence.de>
Hello, 

I am quite new to Spirit. Great work. :) 

I found that (x %y) is not semantically equal to (x >> *(y >> x)). The 
documentation says otherwise.
I'd consider this a bug. Otherwise documentation would have to be changed 
at several places.
Below is a fully working example.

Using MSVC 2015, Boost 1.61, Win32 build.

Regards, Frank


    //-------------------------------------------------------------------
    //  x % y not semantically equivalent to x >> *(y >> x)

    //#define BOOST_SPIRIT_DEBUG
    #include <io.h>
    #include <boost/spirit/include/qi.hpp>
    #include <boost/spirit/repository/include/qi_confix.hpp>
    #include "../compiler/skipper.hpp"
    #define BOOST_SPIRIT_DEBUG
    namespace qi = boost::spirit::qi;

    namespace parser {

        template <typename Iterator>
        struct ident : qi::grammar<Iterator, std::string()>
        {
            ident();
            void test();
            using t_rule = qi::rule<Iterator, std::string()>;
            t_rule id_using_kleene, id_using_string, id_using_symbols, 
id_using_lit;
            std::vector<t_rule*> rules = { &id_using_kleene, 
&id_using_string, &id_using_symbols, &id_using_lit };
 
            qi::symbols<char, std::string> syms;
        };

        template <typename Iterator>
        ident<Iterator>::ident(): ident::base_type(id_using_kleene)
        {
            syms.add("::", "::");

            id_using_kleene = qi::lexeme[(qi::alpha | '_') >> *(qi::alnum 
| '_') 
                >> *(qi::string("::") >> (qi::alpha | '_') >> *(qi::alnum 
| '_'))];
 
            id_using_string = qi::lexeme[(qi::alpha | '_') >> *(qi::alnum 
| '_') % qi::string("::")];
            id_using_symbols = qi::lexeme[(qi::alpha | '_') >> *(qi::alnum 
| '_') % syms];
            id_using_lit = qi::lexeme[(qi::alpha | '_') >> *(qi::alnum | 
'_') % qi::lit("::")];

 
BOOST_SPIRIT_DEBUG_NODES((id_using_kleene)(id_using_string)(id_using_symbols)(id_using_lit))

        }

        template <typename Iterator>
        void ident<Iterator>::test() {
            std::string to_parse = "willy::anton";
            for( std::size_t i = 0; i < rules.size(); i++) {
                std::string result;
                auto b(to_parse.begin()), e(to_parse.end());
                bool success = qi::phrase_parse(b, e, *rules[i], 
qi::space, result);
                if (success && b == e) {
                    std::cout << (*rules[i]).name() << " success. Result: 
" << result << std::endl;
                }
                else {
                    std::cout << (*rules[i]).name() << " failed." << 
std::endl;
                }
            }
            std::cout << std::endl << "Expected behaviour would be result 
== \"willy::anton\" in all three cases but lit." << std::endl;
        }
    }

    typedef std::string::const_iterator iterator_type;


    int main()
    {
        parser::ident<iterator_type> ident;
        ident.test();

        return 0;
    }

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
smime.p7s (application/pkcs7-signature, 5.1 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.