Re: Line continuation characters

[email protected]
Newsgroups perl.recdescent
Message-ID <[email protected]>

I've tried variations of the skip command in the following test program but
still can't get it to parse successfully.  Anyone care to take pity and explain
what I'm doing wrong?

Ken
------------------------------
use Parse::RecDescent;

my @lines = << 'EOINST';
// COMMAND ARG1-VALUE,ARG2-VALUE, +
   ARG3-VALUE,ARG4-VALUE, +
   EVEN-MORE-ARGS
// ANOTHERCOMMAND
* and a comment
* or two
EOINST

my $parse = Parse::RecDescent->new(join '', <DATA>) or die "Bad Grammar!";

$parse->Instructions("@lines") or die "NOT parsable!!\n";

__DATA__

Instructions: command(s)
command: <skip: '(?:[ \t]+|\+[ \t]+\n)+'> commandline /\n/
commandline: '//' /.*/  # real command
commandline: '*' /.*/ # comment
-----------------------------





[email protected] (Randal L. Schwartz) on 10/18/2001 08:01:20 AM

To:   Ted Zlatanov <[email protected]>
cc:   [email protected], [email protected] (Marc Mims) (bcc: Ken
      LaCrosse/FOL/CDI/CHI/US)
Subject:  Re: Line continuation characters



>>>>> "Ted" == Ted Zlatanov <[email protected]> writes:

Ted> [email protected] (Randal L. Schwartz) writes:
>>>>>>> "Marc" == Marc Mims <[email protected]> writes:
>>
Marc> I need to parse a grammar that includes line continuation
Marc> characters.  For example:
>> If the skip between tokens is any combination of spaces, tabs, or "+\n"
combos,
>> then say that:
>>
>> file: command(s)
>> command: <skip: '(?:[ \t]+|\+\n)+'> commandline /\n/
>> commandline: "//" ... # real command
>> commandline: "*" ... # comment
>>
>> You need to match a literal /\n/ at the end of your real
>> command, since that's not matched by this skip.

Ted> Because Marc's grammar seems to be otherwise line-oriented, I'd
Ted> suggest preprocessing the grammar input to merge lines as needed, to
Ted> simplify the grammar.  The major disadvantage would be that line
Ted> numbers would be off when reporting errors though.

"line oriented grammar" => "requires preprocessing" doesn't seem to be
very supportable logic.  There's nothing inherent in P::RD that
requires the grammar to be non-line-oriented.

Now "metagrammar can appear within tokens" implies a need for a
preprocessing layer.  But from what I saw for examples, the
metagrammar (line continuation) appears only outside of tokens, so
that means it can be built into the skip matching logic.

Don't overcomplicate the design... until you have to. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
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.