On Thu, 12 Jul 2007 18:31:43 -0700
Mark Glines <[EMAIL PROTECTED]> wrote:
> So here's a patch. It's a bit quick & dirty, but it'll work. A
> cleaner solution would probably involve adding a fourth returned
> parameter from parse_flags: a line-count. Ends up being the same
> thing, really... just keeps the knowledge of the pmclass line's format
> localized to the parse_flags() function.
...and here's the aforementioned cleaner version. Please review and
apply.
Mark
=== lib/Parrot/Pmc2c/Parser.pm
==================================================================
--- lib/Parrot/Pmc2c/Parser.pm (revision 21442)
+++ lib/Parrot/Pmc2c/Parser.pm (local)
@@ -67,10 +67,10 @@
sub parse_pmc {
my ( $code, $opt ) = @_;
- my ( $pre, $classname, $flags_ref ) = parse_flags( \$code );
+ my ( $pre, $classname, $flags_ref, $pmclass_lines ) = parse_flags( \$code );
my ( $classblock, $post ) = extract_balanced($code);
- my $lineno = 1 + count_newlines($pre);
+ my $lineno = 1 + count_newlines($pre) + $pmclass_lines;
$classblock = substr( $classblock, 1, -1 ); # trim out the { }
my ( @methods, %meth_hash, $class_init );
@@ -174,13 +174,17 @@
=item *
-the name of the class; and
+the name of the class;
=item *
a hash ref containing the flags associated with the class (such as
-C<extends> and C<does>).
+C<extends> and C<does>); and
+=item *
+
+a count of the newlines we consumed while parsing this statement.
+
=back
B<Comments:> Called internally by C<parse_pmc()>.
@@ -197,10 +201,11 @@
my %has_value = map { $_ => 1 } qw(does extends group lib hll maps);
my ( %flags, $parent_nr );
+ my $skipped_lines = 0;
# look through the pmc declaration header for flags such as noinit
- while ( $$c =~ s/^\s*(\w+)//s ) {
- my $flag = $1;
+ while ( $$c =~ s/^(\s*)(\w+)//s ) {
+ my ($whitespace, $flag) = ($1, $2);
if ( $has_value{$flag} ) {
$$c =~ s/^\s+(\w+)//s
or die "Parser error: no value for '$flag'";
@@ -210,6 +215,7 @@
else {
$flags{$flag} = 1;
}
+ $skipped_lines += count_newlines($whitespace);
}
# setup some defaults
@@ -218,7 +224,7 @@
$flags{does}{scalar} = 1 unless $flags{does};
}
- return $pre, $classname, \%flags;
+ return $pre, $classname, \%flags, $skipped_lines;
}
=head3 C<extract_balanced()>