loomis53 has asked for the wisdom of the Perl Monks concerning the following question:
You can parse a nested list like a, b, (c, d (e,f)) I want to deviate from this and enclose the start of the list in parens and return all of the entire text string between the parens, with an array ref for nested parens. So the text: (string one(string two)string three) Returns ['string one', ['string two'],'string three'] I think that this grammar does what I want, but am not sure if it's the best solution:my $grammar = q{ list: <leftop: item ',' item> item: word list <commit> | word word: /\w+/ };
I would like to know if there is a better way to do this. Also, with this approach I cannot have any parens in my text strings within parens. If I wanted to be able to escape parens and include them within the text, how would I go about doing it?my $grammar = q{ list: '(' item(s) ')' item: list <commit> | word word: /[^()]*/ };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse::RecDescent - I'm just not getting it
by ikegami (Patriarch) on May 30, 2006 at 18:07 UTC | |
|
Re: Parse::RecDescent - I'm just not getting it
by blokhead (Monsignor) on May 30, 2006 at 17:57 UTC |