in reply to Re: Parsing Text into Arrays..
in thread Parsing Text into Arrays..

Hi demerphq,
Thanks for the P::RD grammar and the thoughts. If you read my original post to the end, you'd see I did indeed think about using P::RD, but came to the conclusion that thats a lot of overhead for something that can also be done in a couple of subs.
I needed a language parser recently, found P::RD, was impressed, and used it. The docu sure is long, but well-written and easy to understand (in my opinion), I haven't used <leftop> yet, but I managed my task without it, and I guess I'd get this one too if I tried, if not as terse as your soloution :)

Like I mentioned above, this is a real-protocol used to communicate between Muds and a communications server/router. Info here Intermud3 spec if anyones interested. So I'd hope it won't throw empty elements at me, but you never know. :)

As to returning undef without causing the rule to fail, wasn't that just a case of doing:

rule : production { $return = undef; 1; }
? Or am I understanding you wrong?
I think I'll go benchmark these solutions.. Thanks everyone for the answers!

C.

Replies are listed 'Best First'.
Re: Re: Re: Parsing Text into Arrays..
by demerphq (Chancellor) on Jan 21, 2003 at 12:15 UTC
    So I'd hope it won't throw empty elements at me, but you never know. :)

    Ah. But the way I read your sample data it already has implicit empty elements.

    ({ 1, 2, "three", 0, ({ "internal", "array", 0, }), "end", }) ^ ^ | | Here and Here
    If you read my original post to the end, you'd see I did indeed think about using P::RD

    I did read it. I just didn't comprehend it properly. I think its cause my laptop has a small screen and after a while of using it I stop focussing properly. I need to get a monitor at home. Anyway yesterday I seemed to overlook a lot of things. Sorry about that. :-)

    rule : production { $return = undef; 1; }
    ? Or am I understanding you wrong?

    Actually I don't think that works. (At least I tried it and it did the below, but considering my other oversights of yesterday I make no strong claims :-) It seems to be semantically equivelent to

    rule : production { $return = 1; }
    As for leftop it just means you dont have to do tortured things to avoid left recursion which as far as I can tell is involved in this grammar. (I could be wrong).

    Anyway, it was fun. Cheers. Oh when you benchmark dont forget failure cases as well as success. :-)

    --- demerphq
    my friends call me, usually because I'm late....