1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
|
4 |
wakaba |
1.4 |
my $DEBUG = $ENV{DEBUG}; |
5 |
|
|
|
6 |
wakaba |
1.1 |
while (<>) { |
7 |
|
|
s/!!!emit\b/return /; |
8 |
|
|
s{!!!next-input-character;}{q{ |
9 |
|
|
if (@{$self->{char}}) { |
10 |
wakaba |
1.3 |
$self->{next_char} = shift @{$self->{char}}; |
11 |
wakaba |
1.1 |
} else { |
12 |
wakaba |
1.3 |
$self->{set_next_char}->($self); |
13 |
wakaba |
1.1 |
} |
14 |
|
|
}}ge; |
15 |
|
|
s{!!!back-next-input-character\b}{q{unshift @{$self->{char}}, }}ge; |
16 |
|
|
s{!!!parse-error;}{q{$self->{parse_error}->();}}ge; |
17 |
|
|
s{!!!parse-error\b}{q{$self->{parse_error}->}}ge; |
18 |
|
|
s{!!!insert-element-t\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{ |
19 |
|
|
{ |
20 |
|
|
my \$el; |
21 |
|
|
!!!create-element (\$el, $1, $2); |
22 |
|
|
\$insert->(\$el); |
23 |
wakaba |
1.2 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
24 |
wakaba |
1.1 |
} |
25 |
|
|
}}ge; |
26 |
|
|
s{!!!insert-element-t\s*\(([^(),]+)\)\s*;}{qq{ |
27 |
|
|
{ |
28 |
|
|
my \$el; |
29 |
|
|
!!!create-element (\$el, $1); |
30 |
|
|
\$insert->(\$el); |
31 |
wakaba |
1.2 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
32 |
wakaba |
1.1 |
} |
33 |
|
|
}}ge; |
34 |
|
|
s{!!!insert-element\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{ |
35 |
|
|
{ |
36 |
|
|
my \$el; |
37 |
|
|
!!!create-element (\$el, $1, $2); |
38 |
wakaba |
1.2 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
39 |
|
|
push \@{\$self->{open_elements}}, [\$el, $1]; |
40 |
wakaba |
1.1 |
} |
41 |
|
|
}}ge; |
42 |
|
|
s{!!!insert-element\s*\(([^(),]+)\)\s*;}{qq{ |
43 |
|
|
{ |
44 |
|
|
my \$el; |
45 |
|
|
!!!create-element (\$el, $1); |
46 |
wakaba |
1.2 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
47 |
|
|
push \@{\$self->{open_elements}}, [\$el, $1]; |
48 |
wakaba |
1.1 |
} |
49 |
|
|
}}ge; |
50 |
|
|
s{!!!create-element\s*\(([^(),]+),([^(),]+)(?:,([^(),]+))?\)\s*;}{ |
51 |
|
|
my $r = qq{ |
52 |
|
|
$1 = \$self->{document}->create_element_ns |
53 |
|
|
(q<http://www.w3.org/1999/xhtml>, [undef, $2]); |
54 |
|
|
}; |
55 |
|
|
if (defined $3) { |
56 |
|
|
$r .= qq{ |
57 |
|
|
for my \$attr_name (keys %{$3}) { |
58 |
|
|
$1->set_attribute_ns (undef, [undef, \$attr_name], |
59 |
|
|
$3 ->{\$attr_name}->{value}); |
60 |
|
|
} |
61 |
|
|
}; |
62 |
|
|
} |
63 |
|
|
$r; |
64 |
|
|
}ge; # MUST |
65 |
|
|
s{!!!next-token;}{q{$token = $self->_get_next_token;}}ge; |
66 |
|
|
s{!!!back-token;}{q{unshift @{$self->{token}}, $token;}}ge; |
67 |
|
|
s{!!!back-token\s*\(}{q{unshift @{$self->{token}}, (}}ge; |
68 |
wakaba |
1.4 |
s{!!!cp\s*\(\s*(\S+)\s*\)\s*;}{ |
69 |
|
|
$DEBUG ? qq{ |
70 |
wakaba |
1.5 |
#print STDERR "$1, "; |
71 |
wakaba |
1.4 |
\$Whatpm::HTML::Debug::cp_pass->($1) if \$Whatpm::HTML::Debug::cp_pass; |
72 |
|
|
BEGIN { |
73 |
|
|
\$Whatpm::HTML::Debug::cp->{$1} = 1; |
74 |
|
|
} |
75 |
|
|
} : '' |
76 |
|
|
}ge; |
77 |
wakaba |
1.1 |
print; |
78 |
|
|
} |