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