/[pub]/suikawiki/script/bin/mkplugin2.pl
Suika

Diff of /suikawiki/script/bin/mkplugin2.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by wakaba, Fri Dec 26 06:53:48 2003 UTC revision 1.11 by wakaba, Sun Feb 1 12:07:08 2004 UTC
# Line 56  sub barecode ($) { Line 56  sub barecode ($) {
56  sub code ($$) {  sub code ($$) {
57    my ($Info, $code) = @_;    my ($Info, $code) = @_;
58    for (keys %{$Info->{const}}) {    for (keys %{$Info->{const}}) {
59      $code =~ s/\$$_\b/literal $Info->{const}->{$_}/ge;      $code =~ s/\$$_\b/$Info->{const}->{$_}/ge;
60    }    }
61    $code =~ s/__FUNCPACK__/$Info->{module_name}/g;    $code =~ s/__FUNCPACK__/$Info->{module_name}/g;
62    $code;    $code;
# Line 210  sub make_format ($$) { Line 210  sub make_format ($$) {
210      $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal '/'.$name.'/'.$src->get_attribute_value ('Version', default => '').'//']}} = '$module_name';\n};      $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal '/'.$name.'/'.$src->get_attribute_value ('Version', default => '').'//']}} = '$module_name';\n};
211    }    }
212    if (my $type = $src->get_attribute_value ('Type')) {    if (my $type = $src->get_attribute_value ('Type')) {
213        $type .= join '', map {
214                   ';'. $_->local_name .'='. quoted_string $_->inner_text
215                 } sort {
216                   $a->local_name cmp $b->local_name
217                 } @{$src->get_attribute ('Type')->child_nodes};
218      $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal $type.'//']}} = '$module_name';\n};      $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal $type.'//']}} = '$module_name';\n};
219    }    }
220        
# Line 222  sub convert ($$;%) { Line 227  sub convert ($$;%) {
227    my $flag = '//';    my $flag = '//';
228    $flag .= 'f' if $opt{IsFragment};    $flag .= 'f' if $opt{IsFragment};
229    $flag .= 'p' if $opt{IsPlaceholder};    $flag .= 'p' if $opt{IsPlaceholder};
230    if ($Converter->{$opt{Type}.$flag}) {    my $type = $opt{Type} ?
231      $converter = $Converter->{$opt{Type}.$flag};                  $opt{Type} .
232                    SuikaWiki::Format::Definition->__get_param_string
233                      ($opt{Type_param}) : undef;
234      if ($Converter->{$type.$flag}) {
235        $converter = $Converter->{$type.$flag};
236    } elsif ($Converter->{$opt{Name}.'/'.$opt{Version}.$flag}) {    } elsif ($Converter->{$opt{Name}.'/'.$opt{Version}.$flag}) {
237      $converter = $Converter->{'/'.$opt{Name}.'/'.$opt{Version}.$flag};      $converter = $Converter->{'/'.$opt{Name}.'/'.$opt{Version}.$flag};
238    }    }
# Line 240  EOH Line 249  EOH
249          undef $convert;          undef $convert;
250        }        }
251        $r .= make_format_converter ($_, $Info);        $r .= make_format_converter ($_, $Info);
252        } elsif ($_->local_name eq 'WikiForm') {
253          $r .= q(sub wikiform {)."\n".q(my ($self, $source, %opt) = @_;);
254          $r .= line $Info, node_path => qq(Format[module-name()=$module_name]/WikiForm);
255          $r .= code $Info, $_->get_attribute_value ('Main');
256          $r .= line $Info, reset => 1;
257          $r .= qq(}\n);
258        } elsif ($_->local_name eq 'HeadSummary') {
259          $r .= q(sub headsummary {)."\n".q(my ($self, $source, %opt) = @_;);
260          $r .= line $Info, node_path => qq(Format[module-name()=$module_name]/HeadSummary);
261          $r .= code $Info, $_->get_attribute_value ('Main');
262          $r .= line $Info, reset => 1;
263          $r .= qq(}\n);
264        } elsif ($_->local_name eq 'NextIndex') {
265          my $name = $_->get_attribute_value ('Name', default => '');
266          $r .= q(sub next_index_for_).$name
267             .  q( {)."\n".q(my ($self, $source, %opt) = @_;)
268             .  line $Info, node_path => qq(Format[module-name()=$module_name]/NextIndex[Name=$name]);
269          $r .= code $Info, $_->get_attribute_value ('Main');
270          $r .= line $Info, reset => 1;
271          $r .= qq(}\n);
272      } elsif ($_->local_name eq 'Use') {      } elsif ($_->local_name eq 'Use') {
273        $r .= line $Info, node_path => qq(Format[module-name()=$module_name]/Use);        $r .= line $Info, node_path => qq(Format[module-name()=$module_name]/Use);
274        $r .= $_->inner_text;        $r .= $_->inner_text;
# Line 316  EOH Line 345  EOH
345  sub register_plugin_const ($$) {  sub register_plugin_const ($$) {
346    my ($src, $Info) = @_;    my ($src, $Info) = @_;
347    for (@{$src->child_nodes}) {    for (@{$src->child_nodes}) {
348      $Info->{const}->{$_->local_name} = $_->value;      $Info->{const}->{$_->local_name} = literal_or_code $Info, $_->value;
349    }    }
350  }  }
351    
# Line 370  sub make_viewdef ($$) { Line 399  sub make_viewdef ($$) {
399    my $ViewProp = {};    my $ViewProp = {};
400    my $r = '';    my $r = '';
401    $ViewProp->{Name} = n11n $src->get_attribute_value ('Mode');    $ViewProp->{Name} = n11n $src->get_attribute_value ('Mode');
402      $ViewProp->{Name} =~ s/(?<=.)-/_/g;
403    $ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name});    $ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name});
404        
405    $ViewProp->{condition_stringified} = hash    $ViewProp->{condition_stringified} = hash
# Line 385  push \@SuikaWiki::View::Implementation:: Line 415  push \@SuikaWiki::View::Implementation::
415  @{[change_package $Info, $ViewProp->{pack_name}]}  @{[change_package $Info, $ViewProp->{pack_name}]}
416  our \@ISA = q#SuikaWiki::View::template#;  our \@ISA = q#SuikaWiki::View::template#;
417  EOH  EOH
418      
419      my $use = $src->get_attribute ('Use');
420      if (ref $use) {
421        $r .= line $Info, node_path => "ViewDefinition[Mode='$ViewProp->{Name}']/Use";
422        $r .= $use->inner_text . "\n\n";
423      }
424      
425    for (@{$src->child_nodes}) {    for (@{$src->child_nodes}) {
426      if ($_->local_name eq 'template') {      if ($_->local_name eq 'template') {
427        $r .= make_view_template_method ($_, $Info, $ViewProp);        $r .= make_view_template_method ($_, $Info, $ViewProp);
# Line 488  sub make_rule ($$) { Line 525  sub make_rule ($$) {
525    my $type = $src->get_attribute ('Category', make_new_node => 1)->value || [];    my $type = $src->get_attribute ('Category', make_new_node => 1)->value || [];
526    my $name = $src->get_attribute ('Name', make_new_node => 1)->value;    my $name = $src->get_attribute ('Name', make_new_node => 1)->value;
527    $name =~ s/(?<=.)-/_/g;    $name =~ s/(?<=.)-/_/g;
   my $main = line ($Info, node_path => "FormattingRule[name()='@{[list $type]}/$name']/Formatting")  
            . code ($Info, $src->get_attribute_value ('Formatting'));  
528        
529    my $reg_block;    my $reg_block;
530    $reg_block = qr/[^{}]*(?>[^{}]+|{(??{$reg_block})})*/;    $reg_block = qr/[^{}]*(?>[^{}]+|{(??{$reg_block})})*/;
531        my %code;
532    $main = q{my ($f, $rule_name, $p, $o, %opt) = @_;}."\n".$main    for my $codename ([qw/Formatting main/], [qw/After after/],
533      if $main =~ /\$f\b/                      [qw/Before before/], [qw/Pre pre/], [qw/Post post/],
534      or $main =~ /\$rule_name\b/                      [qw/Attribute attr/]) {
535      or $main =~ /\$[opr]\b/      my $main = code $Info, $src->get_attribute_value ($codename->[0]);
536      or $main =~ /[%\$]opt\b/;      next unless $main;
537    if ($main =~ /\$r\b/) {      $main = line ($Info, node_path =>
538      warn qq(Rule @{[list $type]}/$name: Use of \$r is deprecated);                "FormattingRule[name()='@{[list $type]}/$name']/".$codename->[0])
539      $main = q{my $r = '';} . "\n" . $main . "\n"            . $main;
540            . q{$p->{-parent}->append_node ($r, node_or_text => 1);};      
541    }      if ( $main =~ /\$f\b/
542    $main =~ s{__ATTR(TEXT|NODE)?:%(\w+|{$reg_block})(?:->{($reg_block)})?__;}        or $main =~ /\$rule_name\b/
543              {($1 eq 'TEXT' ? '$p->{'.literal_or_code($Info, $2)        or $main =~ /\$[opr]\b/
544                                      .'} = do { my $r = ' : '')        or $main =~ /[%\$]opt\b/
545               .'$f->parse_attr ($p=>'.literal_or_code($Info, $2).', $o, '        or $main =~ /\$param_(?:name|value)\n/) {
546                               .($3?'-parent => '.$3.', ':'')        if ($codename->[0] ne 'Attribute') {
547                               .($1?'-non_parsed_to_node => 1, ':'')          $main = q{my ($f, $rule_name, $p, $o, %opt) = @_;}."\n".$main;
548                               .'%opt)'        } else {
549                               .($1 eq 'TEXT' ? '; ref $r?$r->inner_text:$r}' : '')          $main = q{my ($f, $rule_name, $p, $o, $param_name => $param_value, %opt) = @_;}."\n".$main;
550                               .';'}ge;        }
551          }
552    $main = <<EOH;      if ($main =~ /\$r\b/) {
553          warn qq(Rule @{[list $type]}/$name: Use of \$r is deprecated);
554          $main = q{my $r = '';} . "\n" . $main . "\n"
555                . q{$p->{-parent}->append_node ($r, node_or_text => 1);};
556        }
557        $main =~ s{__ATTR(TEXT|NODE)?:%(\w+|{$reg_block})(?:->{($reg_block)})?__;}
558                  {($1 eq 'TEXT' ? '$p->{'.literal_or_code($Info, $2)
559                                          .'} = do { my $r = ' : '')
560                   .'$f->parse_attr ($p=>'.literal_or_code($Info, $2).', $o, '
561                                   .($3?'-parent => '.$3.', ':'')
562                                   .($1?'-non_parsed_to_node => 1, ':'')
563                                   .'%opt)'
564                                   .($1 eq 'TEXT' ? '; ref $r?$r->inner_text:$r}'
565                                                  : '')
566                                   .';'}ge;
567        $code{$codename->[1]} = barecode "sub {$main}";
568      }
569      
570      my $main = literal {
571        Description => [barecode m13ed_val_list $src, 'Description'],
572        Parameter => {do {
573          my @r;
574          for (@{$src->child_nodes}) {
575            if ($_->local_name eq 'Parameter') {
576              push @r, $_->get_attribute_value ('Name')
577                       => {Type => $_->get_attribute_value ('Type'),
578                           Default => $_->get_attribute_value ('Default'),
579                           Description => [barecode m13ed_val_list $_, 'Description']};
580            }
581          }
582          @r;
583        }},
584        %code,
585      };
586      $main .= line $Info, reset => 1;
587    
588    
589    my  $amain = <<EOH;
590  {  {
591    main => sub {$main},    main => sub {$main},
592  @{[line ($Info, reset => 1)]}  @{[line ($Info, reset => 1)]}
593    Description => [@{[m13ed_val_list $src, 'Description']}],    Description => [@{[m13ed_val_list $src, 'Description']}],
594    Parameter => {@{[do{    Parameter => {@{[do{
     my @r;  
     for (@{$src->child_nodes}) {  
       if ($_->local_name eq 'Parameter') {  
         push @r, $_->get_attribute_value ('Name')  
                  => {Type => $_->get_attribute_value ('Type'),  
                      Default => $_->get_attribute_value ('Default'),  
                      Description => [barecode m13ed_val_list $_, 'Description']};  
       }  
     }  
     list @r;  
595    }]}},    }]}},
596  }  }
597  EOH  EOH

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.11

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24