1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
|
4 |
my $DEBUG = $ENV{DEBUG}; |
5 |
|
6 |
while (<>) { |
7 |
s/!!!emit\b/return /; |
8 |
s{!!!next-input-character;}{q{ |
9 |
if (@{$self->{char}}) { |
10 |
$self->{next_char} = shift @{$self->{char}}; |
11 |
} else { |
12 |
$self->{set_next_char}->($self); |
13 |
} |
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\s*\(}{ |
18 |
q{$self->{parse_error}->(level => $self->{must_level}, } |
19 |
}ge; |
20 |
s{!!!insert-element-t\s*\(([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{ |
21 |
{ |
22 |
my \$el; |
23 |
!!!create-element (\$el, $1, $2, $3); |
24 |
\$insert->(\$el); |
25 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
26 |
} |
27 |
}}ge; |
28 |
s{!!!insert-element-t\s*\(([^(),]+),\s*,([^(),]+)\)\s*;}{qq{ |
29 |
{ |
30 |
my \$el; |
31 |
!!!create-element (\$el, $1,, $2); |
32 |
\$insert->(\$el); |
33 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
34 |
} |
35 |
}}ge; |
36 |
s{!!!insert-element-t\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{ |
37 |
{ |
38 |
my \$el; |
39 |
!!!create-element (\$el, $1, $2); |
40 |
\$insert->(\$el); |
41 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
42 |
} |
43 |
}}ge; |
44 |
s{!!!insert-element-t\s*\(([^(),]+)\)\s*;}{qq{ |
45 |
{ |
46 |
my \$el; |
47 |
!!!create-element (\$el, $1); |
48 |
\$insert->(\$el); |
49 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
50 |
} |
51 |
}}ge; |
52 |
s{!!!insert-element\s*\(([^(),]+),\s*,([^(),]+)\)\s*;}{qq{ |
53 |
{ |
54 |
my \$el; |
55 |
!!!create-element (\$el, $1,, $2); |
56 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
57 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
58 |
} |
59 |
}}ge; |
60 |
s{!!!insert-element\s*\(([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{ |
61 |
{ |
62 |
my \$el; |
63 |
!!!create-element (\$el, $1, $2, $3); |
64 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
65 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
66 |
} |
67 |
}}ge; |
68 |
s{!!!insert-element\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{ |
69 |
{ |
70 |
my \$el; |
71 |
!!!create-element (\$el, $1, $2); |
72 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
73 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
74 |
} |
75 |
}}ge; |
76 |
s{!!!insert-element\s*\(([^(),]+)\)\s*;}{qq{ |
77 |
{ |
78 |
my \$el; |
79 |
!!!create-element (\$el, $1); |
80 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
81 |
push \@{\$self->{open_elements}}, [\$el, $1]; |
82 |
} |
83 |
}}ge; |
84 |
s{!!!create-element\s*\(([^(),]+),([^(),]+)(?:,([^(),]*)(?>,([^(),]+))?)?\)\s*;}{ |
85 |
my $l_var = $1; |
86 |
my $r = qq{ |
87 |
$l_var = \$self->{document}->create_element_ns |
88 |
(q<http://www.w3.org/1999/xhtml>, [undef, $2]); |
89 |
}; |
90 |
if (defined $3 and length $3) { |
91 |
$r .= qq{ |
92 |
for my \$attr_name (keys %{$3}) { |
93 |
$l_var->set_attribute_ns (undef, [undef, \$attr_name], |
94 |
$3 ->{\$attr_name}->{value}); |
95 |
} |
96 |
}; |
97 |
} |
98 |
if (defined $4) { |
99 |
my $token_var = $4; |
100 |
$token_var =~ s/^\s+//; |
101 |
$token_var =~ s/\s+$//; |
102 |
$r .= qq{ |
103 |
$l_var->set_user_data (manakai_source_line => $token_var\->{line}) |
104 |
if defined $token_var\->{line}; |
105 |
$l_var->set_user_data (manakai_source_column => $token_var\->{column}) |
106 |
if defined $token_var\->{column}; |
107 |
}; |
108 |
## TODO: In future version, it should be allowed for an application |
109 |
## developer to choose whether these information should be kept |
110 |
## for tracking or not for performance by some means. |
111 |
} |
112 |
$r; |
113 |
}ge; # MUST |
114 |
s{!!!next-token;}{q{$token = $self->_get_next_token;}}ge; |
115 |
s{!!!back-token;}{q{unshift @{$self->{token}}, $token;}}ge; |
116 |
s{!!!back-token\s*\(}{q{unshift @{$self->{token}}, (}}ge; |
117 |
s{!!!cp\s*\(\s*(\S+)\s*\)\s*;}{ |
118 |
$DEBUG ? qq{ |
119 |
#print STDERR "$1, "; |
120 |
\$Whatpm::HTML::Debug::cp_pass->($1) if \$Whatpm::HTML::Debug::cp_pass; |
121 |
BEGIN { |
122 |
\$Whatpm::HTML::Debug::cp->{$1} = 1; |
123 |
} |
124 |
} : '' |
125 |
}ge; |
126 |
print; |
127 |
} |