Thomas Taylor | 3 Jun 08:24
Picon
Picon
Favicon

Nabialek trick

Hi all,

Just wanted to point out that although the example given in the
documentation in Techniques/Nabialek trick is functional, I recommend an
additional alert: If the rule that is used as target (the rest rule in the
example) is declared but not defined everything is fine. However when this
rule is also defined unexplained behaviour is the result. In my case
valgrind detected lots of invalid reads (trying to read parts of previously
free'd memory) and various legal code snippets suddenly seemed to cause a
segmentation fault.
Maybe this requirement to declare but not define the nabialek trick target
rule can be deduced from the documentation, but it was not very obvious to
me.

Regards,

Thomas

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Thomas Taylor | 3 Jun 09:54
Picon
Picon
Favicon

Re: Signature of skip parser, and why does space_p work but not blank_p?

Thomas Taylor wrote:
> Actually if I am not mistaken the parse function should be happy with any
> parser/rule/grammar as the skip-parser.
Very true, and it works if you do not stumble down all the pits like I do.

> Compile error
> result = parse(Start, End, SomeGrammar, SkipGrammar);
I managed to resolve this problem. See below...

> with SkipGrammar of type
> struct skip_grammar : public boost::spirit::grammar<skip_grammar>
> {
> template <typename ScannerT> struct definition
> {
> definition(skip_grammar const& self) {}
> boost::spirit::rule<ScannerT> const& start() const
> {
> return boost::spirit::space_p;  // This is an evil line!
> }
> };
> };
The so marked evil line is bad because it returns a reference to a temporary
object!

What really caused my problem was something completely different, as I had a
line in my SkipGrammer like this:
> skiprule = '\t' | ' ';
Quite obviously this is bad as explained in the operands section of the
documentation. To fix this the line should be something like this:
> skiprule = boost::spirit::ch_p('\t') | ' ';
(Continue reading)

Joel de Guzman | 3 Jun 10:43
Picon
Favicon

Re: Signature of skip parser, and why does space_p work but not blank_p?

Thomas Taylor wrote:
> Thomas Taylor wrote:
>> Actually if I am not mistaken the parse function should be happy with any
>> parser/rule/grammar as the skip-parser.
> Very true, and it works if you do not stumble down all the pits like I do.
> 
>> Compile error
>> result = parse(Start, End, SomeGrammar, SkipGrammar);
> I managed to resolve this problem. See below...
> 
>> with SkipGrammar of type
>> struct skip_grammar : public boost::spirit::grammar<skip_grammar>
>> {
>> template <typename ScannerT> struct definition
>> {
>> definition(skip_grammar const& self) {}
>> boost::spirit::rule<ScannerT> const& start() const
>> {
>> return boost::spirit::space_p;  // This is an evil line!
>> }
>> };
>> };
> The so marked evil line is bad because it returns a reference to a temporary
> object!

FWIW, Spirit-2 fixes all these problems because the rule now
has true C++ copy/assign semantics.

Regards
--

-- 
(Continue reading)

Eduardo Spagiari | 3 Jun 14:16
Picon

Sql Parce with actors

Hi,

I´m have a problem with a sql parse recurcive. sample:


Select mytable.myfielda, mysubquery.myfieldb from mytable, (select myfieldb from myanothertable) mysubquery

it´s possible know whats tables of select and tables of subquery?

thanks,

Eduardo
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Christopher Currie | 4 Jun 07:30
Picon
Gravatar

Re: [wave][spirit2] Converting Wave pattern_and parser

One weakness that my posted implementation of pattern_and using spirit2 
has is that the error messaging for the expression is really awkward. 
This may be a fault of expression templates in general, but as an example:

  BOOST_TEST(test(T_ASSIGN, pattern_( T_ASSIGN )));

fails to compile, not with a sensible error message that lets me know 
that I don't have enough arguments, but with a somewhat opaque message 
involving "mpl_::failed" and "xpr_is_not_convertible_to_a_parser". What 
I don't know is if there's anything I could do to make it better, with 
better usage of spirit2 and/or proto.

Thanks,
Christopher

Hartmut Kaiser wrote:
> Christopher,
> 
>> I've been learning more spirit2, and my particular interest is in using
>> Wave with spirit2. I understand that Wave uses spirit1 in it's
>> implementation, but it should still be possible to use the Wave context
>> iterators in a spirit2 parser.
> 
> Just a quick answer for now (will answer in more detail over the weekend):
> yes it should be possible to use the Wave iterators with Spirit2, but I
> never tried.
> 
> Regards Hartmut
> 
> 
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Andy Elvey | 4 Jun 08:36
Picon
Favicon
Gravatar

Re: Sql Parce with actors

Eduardo Spagiari wrote:
>
> Hi,
>
> I´m have a problem with a sql parse recurcive. sample:
>
>
> Select mytable.myfielda, mysubquery.myfieldb from mytable, (select 
> myfieldb from myanothertable) mysubquery
>
> it´s possible know whats tables of select and tables of subquery?
>
> thanks,
>
> Eduardo
Hi Eduardo -

I'm the author of the small "toy SQL" parser for Spirit, so I'll see if 
I can help here... :-) 

The first thing I should mention is that the SQL parser is very much 
meant as a "toy SQL" parser - not for "real-world" or production  use. 
It only parses the "select" clause of SQL and even then, not all of that 
is supported. It's been a while since I updated or used it, but iirc 
sub-queries like the one that you've described aren't supported (not 
yet, anyway... ;)  ).  

Having said  that, just in the last few minutes I've downloaded the SQL 
parser and made a small modification to it.  It is now able to parse 
phrases like -

Select mytable.myfielda, mysubquery.myfieldb from mytable;

Select mytable.myfielda as test1, mysubquery.myfieldb as test2 from mytable;

( Don't forget the semicolon at the end of the SQL query.... ) 

I'll email the amended code to you in a few minutes (direct to your 
address to avoid flooding the list with m attachment... :)  ) 
Enjoy!  HTH - Bye for now -
- Andy

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
JānisRukšāns | 5 Jun 02:21
Picon

Spirit grammar for IPv6

>
Hi,

Parsing IPv6 literals is something I've been trying to do for the last couple of
days and it seems I've finally got it right. Any comments are welcome.

// might have typos and friends
// I factored it out from a larger grammar

uint_parser<unsigned, 10, 1, 3> dec3_p;
uint_parser<unsigned, 16, 1, 4> hex4_p;

struct num_groups :
    public boost::spirit::closure<
        num_groups,
        unsigned int
    >
{
    member1 g;
};

struct ipv6_grammar :
    public grammar<ipv6_grammar>
{

    template <typename ScannerT>
    struct definition {

        typedef rule<ScannerT> rule_t;

        definition(const ipv6_grammar & self) {
            root = (
                ipv6    =   fullform | shortform,

                fullform
                        =   repeat_p ( 6 ) [ hex4_p >> ':' ]
                            >> ( ipv4 | hex4_p >> ':' >> hex4_p ),

                shortform
                        =   eps_p [ shortform.g = 7u ]
                            >> !firstpart >> "::"
                            >> if_p ( shortform.g ) [
                                !secondpart
                            ],

                firstpart
                        =   hex4_p [ --shortform.g ] >> *(
                                if_p ( shortform.g ) [
                                    ':' >> hex4_p [ --shortform.g ]
                                ]. else_p [
                                    nothing_p
                                ]
                            ),

                secondpart
                        =   if_p ( shortform.g > 1u ) [
                                ( ( hex4_p >> ':' ) [ --shortform.g ] >>
secondpart ) | ipv4
                            ]. else_p [
                                hex4_p
                            ],

                ipv4    =   dec_byte >> '.' >> dec_byte >> '.' >> dec_byte >>
'.' >> dec_byte,

                dec_byte
                        =   limit_d(0u, 255u) [ dec3_p ]
            );
        }

        const rule_t &
        start() const {
            return root;
        }

    private:
        rule_t                            root;

        subrule<0>                        ipv6;
        subrule<1>                        fullform;
        subrule<2, num_groups::context_t> shortform;
        subrule<3>                        firstpart;
        subrule<4>                        secondpart;
        subrule<5>                        ipv4;
        subrule<6>                        dec_byte;

    };

};

If anyone wants to reuse this in his/her code, feel free.

Regards,
Jānis

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
JānisRukšāns | 5 Jun 17:12
Picon

Re: Compiler internal error, second try

White Wolf <wolof <at> freemail.hu> writes:

> 
> Hi,
> 
> I am trying to build a (tiny bit modified, only stuff removed) version  
> of the cpp_lexer example on openSuse 10.3, that has g++ 4.2.1 for a  
> compiler.  I am using Boost 1.35.0.
> 
> I get an internal error in subrule.hpp:
> 
> /usr/include/boost/spirit/core/non_terminal/subrule.hpp:179: internal  
> compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:4971
> 
> The actual message is a lot longer, this is only the part showing what  
> error I hit.  The same code compiles and runs fine on Mac (4.0.2 gcc).
> 
> Anyone have seen this?  Any hints how to avoid this compiler error?   
> Perhaps there is already a patch (to Spirit) I just don't know about  
> it...

I'm getting error messages much like your's if I'm using closures that are
defined in an unnamed namespace.

namespace {

    struct int_closure :
        public boost::spirit::closure<
            int_closure,
            int
        >
    {
        member1 value;
    };

    struct test_grammar :
        public grammar<test_grammar>
    {
        template <typename ScannerT>
        struct definition {
            typedef rule<ScannerT> rule_t;

            definition(const test_grammar & self) {
                root = (
                    test_sub = int_p [ test_sub.value = arg1 ]
                );
            }

            const rule_t &
            start() const {
                return root;
            };

        private:
            rule_t root;
            subrule<0, int_closure::context_t> test_sub;
        };
    };

}

/usr/include/boost/spirit/core/non_terminal/subrule.hpp:180: internal compiler
error: in make_rtl_for_nonlocal_decl, at cp/decl.c:5069

Using Boost 1.33.1 and GCC 4.1.2. Moving int_closure out of any unnamed
namespaces fixes the problem.

--
Jānis

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Hartmut Kaiser | 5 Jun 18:35
Picon
Gravatar

Re: [wave][spirit2] Converting Wave pattern_and parser

> One weakness that my posted implementation of pattern_and using spirit2
> has is that the error messaging for the expression is really awkward.
> This may be a fault of expression templates in general, but as an
> example:
> 
>   BOOST_TEST(test(T_ASSIGN, pattern_( T_ASSIGN )));
> 
> fails to compile, not with a sensible error message that lets me know
> that I don't have enough arguments, but with a somewhat opaque message
> involving "mpl_::failed" and "xpr_is_not_convertible_to_a_parser". What
> I don't know is if there's anything I could do to make it better, with
> better usage of spirit2 and/or proto.

Ohh, and we thought, that's as good as it can get :-P
Actually the instantiation stack in the error message for this is not very
deep, so it should be at least easy to pinpoint the source of the error.

Regards Hartmut

PS: I know I promised to get back to you over the last weekend, but didn't
do so. I'm sorry... Too much things are going on here at the same time.

> 
> Thanks,
> Christopher
> 
> Hartmut Kaiser wrote:
> > Christopher,
> >
> >> I've been learning more spirit2, and my particular interest is in
> using
> >> Wave with spirit2. I understand that Wave uses spirit1 in it's
> >> implementation, but it should still be possible to use the Wave
> context
> >> iterators in a spirit2 parser.
> >
> > Just a quick answer for now (will answer in more detail over the
> weekend):
> > yes it should be possible to use the Wave iterators with Spirit2, but
> I
> > never tried.
> >
> > Regards Hartmut
> >
> >
> >
> > ---------------------------------------------------------------------
> ----
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> 
> 
> -----------------------------------------------------------------------
> --
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Spirit-general mailing list
> Spirit-general <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/spirit-general

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
Joel de Guzman | 6 Jun 06:00
Picon
Favicon

Re: [wave][spirit2] Converting Wave pattern_and parser

Hartmut Kaiser wrote:
>> One weakness that my posted implementation of pattern_and using spirit2
>> has is that the error messaging for the expression is really awkward.
>> This may be a fault of expression templates in general, but as an
>> example:
>>
>>   BOOST_TEST(test(T_ASSIGN, pattern_( T_ASSIGN )));
>>
>> fails to compile, not with a sensible error message that lets me know
>> that I don't have enough arguments, but with a somewhat opaque message
>> involving "mpl_::failed" and "xpr_is_not_convertible_to_a_parser". What
>> I don't know is if there's anything I could do to make it better, with
>> better usage of spirit2 and/or proto.
> 
> Ohh, and we thought, that's as good as it can get :-P

Yeah :-; Have you seen Spirit-1's error messages? It
was ghastly. I thought people would be thankful for Spirit-2's
'somewhat opaque message involving "mpl_::failed" and
"xpr_is_not_convertible_to_a_parser"'

Oh well...

I guess people want to know why the expression failed, not
just that it failed.

In Spirit 2, there's what's called 'expectation'. Example:

     ('*' > factor)

Notice that we have > and not >>. It's a deterministic point. When
you get a '*' you definitely must have a factor next. Otherwise,
we'll throw an exception (we will not backtrack and try other
routes).

We can probably have something like that at the proto-grammar level.
I'd pass it on to our good friend, Eric. Eric? Maybe we can add
something like Spirit-2's 'expectations' to the proto sub-grammars?

Regards,
--

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

Gmane