--- suikawiki/script/bin/mkplugin2.pl 2003/11/25 12:47:19 1.5 +++ suikawiki/script/bin/mkplugin2.pl 2003/11/26 09:11:01 1.6 @@ -1,6 +1,6 @@ #!/usr/bin/perl use strict; -our $VERSION = do{my @r=(q$Revision: 1.5 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; +our $VERSION = do{my @r=(q$Revision: 1.6 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; require Message::Markup::SuikaWikiConfig20::Parser; { @@ -75,6 +75,28 @@ $s =~ s/([\\"])/\\$1/g; '"'.$s.'"'; } +sub line ($;%) { + my ($Info, %opt) = @_; + + unless ($opt{file}) { + if ($opt{reset}) { + $opt{file} = sprintf '(WikiPlugin module %s, chunk %d)', + $Info->{Name}, + ++$Info->{chunk_count}; + } elsif ($opt{realfile}) { + $opt{file} = sprintf '(WikiPlugin module %s, chunk from %s)', + $Info->{Name}, + $opt{realfile}; + } else { + $opt{file} = sprintf '(WikiPlugin module %s, block %s)', + $Info->{Name}, + $opt{node_path}; + } + } + + $opt{file} =~ s/"/''/g; + sprintf '%s#line %d "%s"%s', "\n", $opt{line_no} || 1, $opt{file}, "\n"; +} my $parser = Message::Markup::SuikaWikiConfig20::Parser->new; my $plugins = $parser->parse_text ($src); @@ -133,7 +155,9 @@ my $use = $meta->get_attribute ('Use'); if (ref $use) { print change_package \%Info, $Info{module_name}; - print $use->inner_text; + print line \%Info, node_path => 'Plugin/Use'; + print $use->inner_text, "\n"; + print line \%Info, reset => 1; } for (@{$plugins->child_nodes}) { @@ -181,6 +205,7 @@ $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal $type.'//']}} = '$module_name';\n}; } + $r .= line $Info, line_no => __LINE__ + 2, realfile => __FILE__; $r .= <<'EOH'; our $Converter; sub convert ($$;%) { @@ -199,13 +224,19 @@ } EOH + my $reset = 0; for (@{$src->child_nodes}) { if ($_->local_name eq 'Converter') { + $r .= line $Info, reset => 1 unless $reset; $r .= make_format_converter ($_, $Info); + $reset = 1; } elsif ($_->local_name eq 'Use') { + $r .= line $Info, node_path => qq(Format[module-name()=$module_name]/Use); $r .= $_->inner_text; + $reset = 0; } } + $r .= line $Info, reset => 1 unless $reset; $r; } @@ -237,7 +268,12 @@ if $src->get_attribute_value ('IsPlaceholder'); $def{Main} = $src->get_attribute_value ('Main'); - $def{Main} = 'my $r;'.$def{Main}.'$r' if $def{Main} =~ /\$r\b/; + $def{Main} = line ($Info, node_path => '//Converter/Main') + . $def{Main} + . line ($Info, reset => 1); + if ($def{Main} =~ /\$r\b/) { + $def{Main} = 'my $r;'."\n".$def{Main}."\n".'$r'; + } $def{Main} = barecode code $Info, 'sub {my ($self, $source, $opt) = @_;' . $def{Main} . '}'; @@ -257,10 +293,13 @@ sub make_function ($$) { my ($src, $Info) = @_; ## TODO: support of ARGV property + my $name; my $r = <{module_name}]} -sub @{[$src->get_attribute_value ('Name')]} { - @{[code $Info, $src->get_attribute_value ('Main')]} +sub @{[$name = $src->get_attribute_value ('Name')]} { +@{[line $Info, node_path => "Function[Name='$name']/Main"]}@{[ + code $Info, $src->get_attribute_value ('Main') +]}@{[line $Info, reset => 1]} } EOH } @@ -321,7 +360,7 @@ my ($src, $Info) = @_; my $ViewProp = {}; my $r = ''; - $ViewProp->{Name} = n11n $src->get_attribute ('Mode')->value; + $ViewProp->{Name} = n11n $src->get_attribute_value ('Mode'); $ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name}); $ViewProp->{condition_stringified} = hash @@ -341,14 +380,17 @@ if ($_->local_name eq 'template') { $r .= make_view_template_method ($_, $Info); } elsif ($_->local_name eq 'method') { + my $method_name = $_->get_attribute_value ('Name'); $r .= ({ main => q(sub main ($$) {)."\n".q(my ($self, $opt) = @_;)."\n", main_pre => q(sub main_pre ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n", main_post => q(sub main_post ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n", - }->{$_->get_attribute ('Name')->value} - ||qq(sub @{[$_->get_attribute ('Name')->value]} {\n)) + }->{$method_name} + ||qq(sub @{[$method_name]} {\n)) + . line ($Info, node_path => "ViewDefinition[Mode='$ViewProp->{Name}']/method[Name='$method_name']") . code ($Info, $_->value) - . qq(\n}\n); + . line ($Info, reset => 1) + . qq(}\n); } } my $prop = {Name => $ViewProp->{Name}, @@ -432,7 +474,9 @@ my $type = $src->get_attribute ('Category', make_new_node => 1)->value || []; my $name = $src->get_attribute ('Name', make_new_node => 1)->value; $name =~ s/(?<=.)-/_/g; - my $main = code $Info, $src->get_attribute_value ('Formatting'); + my $main = line ($Info, node_path => "FormattingRule[name()='@{[list $type]}/$name']/Formatting") + . code ($Info, $src->get_attribute_value ('Formatting')) + . line ($Info, reset => 1); my $reg_block; $reg_block = qr/[^{}]*(?>[^{}]+|{(??{$reg_block})})*/;