75 |
$s =~ s/([\\"])/\\$1/g; |
$s =~ s/([\\"])/\\$1/g; |
76 |
'"'.$s.'"'; |
'"'.$s.'"'; |
77 |
} |
} |
78 |
|
sub line ($;%) { |
79 |
|
my ($Info, %opt) = @_; |
80 |
|
|
81 |
|
unless ($opt{file}) { |
82 |
|
if ($opt{reset}) { |
83 |
|
$opt{file} = sprintf '(WikiPlugin module %s, chunk %d)', |
84 |
|
$Info->{Name}, |
85 |
|
++$Info->{chunk_count}; |
86 |
|
} elsif ($opt{realfile}) { |
87 |
|
$opt{file} = sprintf '(WikiPlugin module %s, chunk from %s)', |
88 |
|
$Info->{Name}, |
89 |
|
$opt{realfile}; |
90 |
|
} else { |
91 |
|
$opt{file} = sprintf '(WikiPlugin module %s, block %s)', |
92 |
|
$Info->{Name}, |
93 |
|
$opt{node_path}; |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
|
$opt{file} =~ s/"/''/g; |
98 |
|
sprintf '%s#line %d "%s"%s', "\n", $opt{line_no} || 1, $opt{file}, "\n"; |
99 |
|
} |
100 |
|
|
101 |
my $parser = Message::Markup::SuikaWikiConfig20::Parser->new; |
my $parser = Message::Markup::SuikaWikiConfig20::Parser->new; |
102 |
my $plugins = $parser->parse_text ($src); |
my $plugins = $parser->parse_text ($src); |
155 |
my $use = $meta->get_attribute ('Use'); |
my $use = $meta->get_attribute ('Use'); |
156 |
if (ref $use) { |
if (ref $use) { |
157 |
print change_package \%Info, $Info{module_name}; |
print change_package \%Info, $Info{module_name}; |
158 |
print $use->inner_text; |
print line \%Info, node_path => 'Plugin/Use'; |
159 |
|
print $use->inner_text, "\n"; |
160 |
|
print line \%Info, reset => 1; |
161 |
} |
} |
162 |
|
|
163 |
for (@{$plugins->child_nodes}) { |
for (@{$plugins->child_nodes}) { |
205 |
$r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal $type.'//']}} = '$module_name';\n}; |
$r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal $type.'//']}} = '$module_name';\n}; |
206 |
} |
} |
207 |
|
|
208 |
|
$r .= line $Info, line_no => __LINE__ + 2, realfile => __FILE__; |
209 |
$r .= <<'EOH'; |
$r .= <<'EOH'; |
210 |
our $Converter; |
our $Converter; |
211 |
sub convert ($$;%) { |
sub convert ($$;%) { |
224 |
} |
} |
225 |
EOH |
EOH |
226 |
|
|
227 |
|
my $reset = 0; |
228 |
for (@{$src->child_nodes}) { |
for (@{$src->child_nodes}) { |
229 |
if ($_->local_name eq 'Converter') { |
if ($_->local_name eq 'Converter') { |
230 |
|
$r .= line $Info, reset => 1 unless $reset; |
231 |
$r .= make_format_converter ($_, $Info); |
$r .= make_format_converter ($_, $Info); |
232 |
|
$reset = 1; |
233 |
} elsif ($_->local_name eq 'Use') { |
} elsif ($_->local_name eq 'Use') { |
234 |
|
$r .= line $Info, node_path => qq(Format[module-name()=$module_name]/Use); |
235 |
$r .= $_->inner_text; |
$r .= $_->inner_text; |
236 |
|
$reset = 0; |
237 |
} |
} |
238 |
} |
} |
239 |
|
$r .= line $Info, reset => 1 unless $reset; |
240 |
|
|
241 |
$r; |
$r; |
242 |
} |
} |
268 |
if $src->get_attribute_value ('IsPlaceholder'); |
if $src->get_attribute_value ('IsPlaceholder'); |
269 |
|
|
270 |
$def{Main} = $src->get_attribute_value ('Main'); |
$def{Main} = $src->get_attribute_value ('Main'); |
271 |
$def{Main} = 'my $r;'.$def{Main}.'$r' if $def{Main} =~ /\$r\b/; |
$def{Main} = line ($Info, node_path => '//Converter/Main') |
272 |
|
. $def{Main} |
273 |
|
. line ($Info, reset => 1); |
274 |
|
if ($def{Main} =~ /\$r\b/) { |
275 |
|
$def{Main} = 'my $r;'."\n".$def{Main}."\n".'$r'; |
276 |
|
} |
277 |
$def{Main} = barecode code $Info, |
$def{Main} = barecode code $Info, |
278 |
'sub {my ($self, $source, $opt) = @_;' |
'sub {my ($self, $source, $opt) = @_;' |
279 |
. $def{Main} . '}'; |
. $def{Main} . '}'; |
293 |
sub make_function ($$) { |
sub make_function ($$) { |
294 |
my ($src, $Info) = @_; |
my ($src, $Info) = @_; |
295 |
## TODO: support of ARGV property |
## TODO: support of ARGV property |
296 |
|
my $name; |
297 |
my $r = <<EOH; |
my $r = <<EOH; |
298 |
@{[change_package $Info, $Info->{module_name}]} |
@{[change_package $Info, $Info->{module_name}]} |
299 |
sub @{[$src->get_attribute_value ('Name')]} { |
sub @{[$name = $src->get_attribute_value ('Name')]} { |
300 |
@{[code $Info, $src->get_attribute_value ('Main')]} |
@{[line $Info, node_path => "Function[Name='$name']/Main"]}@{[ |
301 |
|
code $Info, $src->get_attribute_value ('Main') |
302 |
|
]}@{[line $Info, reset => 1]} |
303 |
} |
} |
304 |
EOH |
EOH |
305 |
} |
} |
360 |
my ($src, $Info) = @_; |
my ($src, $Info) = @_; |
361 |
my $ViewProp = {}; |
my $ViewProp = {}; |
362 |
my $r = ''; |
my $r = ''; |
363 |
$ViewProp->{Name} = n11n $src->get_attribute ('Mode')->value; |
$ViewProp->{Name} = n11n $src->get_attribute_value ('Mode'); |
364 |
$ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name}); |
$ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name}); |
365 |
|
|
366 |
$ViewProp->{condition_stringified} = hash |
$ViewProp->{condition_stringified} = hash |
380 |
if ($_->local_name eq 'template') { |
if ($_->local_name eq 'template') { |
381 |
$r .= make_view_template_method ($_, $Info); |
$r .= make_view_template_method ($_, $Info); |
382 |
} elsif ($_->local_name eq 'method') { |
} elsif ($_->local_name eq 'method') { |
383 |
|
my $method_name = $_->get_attribute_value ('Name'); |
384 |
$r .= ({ |
$r .= ({ |
385 |
main => q(sub main ($$) {)."\n".q(my ($self, $opt) = @_;)."\n", |
main => q(sub main ($$) {)."\n".q(my ($self, $opt) = @_;)."\n", |
386 |
main_pre => q(sub main_pre ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n", |
main_pre => q(sub main_pre ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n", |
387 |
main_post => q(sub main_post ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n", |
main_post => q(sub main_post ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n", |
388 |
}->{$_->get_attribute ('Name')->value} |
}->{$method_name} |
389 |
||qq(sub @{[$_->get_attribute ('Name')->value]} {\n)) |
||qq(sub @{[$method_name]} {\n)) |
390 |
|
. line ($Info, node_path => "ViewDefinition[Mode='$ViewProp->{Name}']/method[Name='$method_name']") |
391 |
. code ($Info, $_->value) |
. code ($Info, $_->value) |
392 |
. qq(\n}\n); |
. line ($Info, reset => 1) |
393 |
|
. qq(}\n); |
394 |
} |
} |
395 |
} |
} |
396 |
my $prop = {Name => $ViewProp->{Name}, |
my $prop = {Name => $ViewProp->{Name}, |
474 |
my $type = $src->get_attribute ('Category', make_new_node => 1)->value || []; |
my $type = $src->get_attribute ('Category', make_new_node => 1)->value || []; |
475 |
my $name = $src->get_attribute ('Name', make_new_node => 1)->value; |
my $name = $src->get_attribute ('Name', make_new_node => 1)->value; |
476 |
$name =~ s/(?<=.)-/_/g; |
$name =~ s/(?<=.)-/_/g; |
477 |
my $main = code $Info, $src->get_attribute_value ('Formatting'); |
my $main = line ($Info, node_path => "FormattingRule[name()='@{[list $type]}/$name']/Formatting") |
478 |
|
. code ($Info, $src->get_attribute_value ('Formatting')) |
479 |
|
. line ($Info, reset => 1); |
480 |
|
|
481 |
my $reg_block; |
my $reg_block; |
482 |
$reg_block = qr/[^{}]*(?>[^{}]+|{(??{$reg_block})})*/; |
$reg_block = qr/[^{}]*(?>[^{}]+|{(??{$reg_block})})*/; |