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_buffer_pos} < length $self->{char_buffer}) { |
10 |
$self->{line_prev} = $self->{line}; |
11 |
$self->{column_prev} = $self->{column}; |
12 |
$self->{column}++; |
13 |
$self->{nc} |
14 |
= ord substr ($self->{char_buffer}, $self->{char_buffer_pos}++, 1); |
15 |
} else { |
16 |
$self->{set_nc}->($self); |
17 |
} |
18 |
}}ge; |
19 |
s{!!!nack\s*\(\s*'([^']+)'\s*\)\s*;}{ |
20 |
($DEBUG ? qq{ |
21 |
if (\$self->{self_closing}) { |
22 |
!!!cp ('$1.2'); |
23 |
} else { |
24 |
!!!cp ('$1.3'); |
25 |
} |
26 |
} : '') |
27 |
}ge; |
28 |
s{!!!ack\s*(?>\([^)]*\)\s*)?;}{q{delete $self->{self_closing};}}ge; |
29 |
s{!!!ack-later\s*(?>\([^)]*\)\s*)?;}{}ge; |
30 |
s{!!!insert-element-f\s*\(([^(),]+),([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{ |
31 |
{ |
32 |
my \$el; |
33 |
!!!create-element (\$el, $1, $2, $3, $4); |
34 |
\$insert->(\$el); |
35 |
push \@{\$self->{open_elements}}, [\$el, (\$el_category_f->{$1}->{$2} || 0) | FOREIGN_EL]; |
36 |
|
37 |
if ($3\->{xmlns} and $3\->{xmlns}->{value} ne ($1)) { |
38 |
!!!parse-error (type => 'bad namespace', token => $4); |
39 |
## TODO: Error type documentation |
40 |
} |
41 |
if ($3\->{'xmlns:xlink'} and |
42 |
$3\->{'xmlns:xlink'}->{value} ne q<http://www.w3.org/1999/xlink>) { |
43 |
!!!parse-error (type => 'bad namespace', token => $4); |
44 |
} |
45 |
} |
46 |
}}ge; |
47 |
s{!!!insert-element-t\s*\(([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{ |
48 |
{ |
49 |
my \$el; |
50 |
!!!create-element (\$el, \$HTML_NS, $1, $2, $3); |
51 |
\$insert->(\$el); |
52 |
push \@{\$self->{open_elements}}, [\$el, \$el_category->{$1} || 0]; |
53 |
} |
54 |
}}ge; |
55 |
s{!!!insert-element\s*\(([^(),]+),\s*,([^(),]+)\)\s*;}{qq{ |
56 |
{ |
57 |
my \$el; |
58 |
!!!create-element (\$el, \$HTML_NS, $1,, $2); |
59 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
60 |
push \@{\$self->{open_elements}}, [\$el, \$el_category->{$1} || 0]; |
61 |
} |
62 |
}}ge; |
63 |
s{!!!insert-element\s*\(([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{ |
64 |
{ |
65 |
my \$el; |
66 |
!!!create-element (\$el, \$HTML_NS, $1, $2, $3); |
67 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
68 |
push \@{\$self->{open_elements}}, [\$el, \$el_category->{$1} || 0]; |
69 |
} |
70 |
}}ge; |
71 |
s{!!!create-element\s*\(([^(),]+),\s*([^(),]+),([^(),]+)(?:,([^(),]*)(?>,([^(),]+))?)?\)\s*;}{ |
72 |
my ($l_var, $nsuri, $lname, $attrs, $token_var) = ($1, $2, $3, $4, $5); |
73 |
$nsuri =~ s/^\s+//; |
74 |
$nsuri =~ s/\s+\z//; |
75 |
my $r = qq{ |
76 |
$l_var = \$self->{document}->create_element_ns |
77 |
($nsuri, [undef, $lname]); |
78 |
}; |
79 |
if (defined $attrs and length $attrs) { |
80 |
my $attr_xname; |
81 |
if ($nsuri eq q<$HTML_NS>) { |
82 |
$attr_xname = q[undef, [undef, $attr_name]]; |
83 |
} else { |
84 |
## NOTE: "Adjust SVG attributes" (SVG only), |
85 |
## "adjust MathML attributes" (MathML only), and |
86 |
## "adjust foreign attributes". |
87 |
$attr_xname = qq[ |
88 |
\@{ |
89 |
\$foreign_attr_xname->{\$attr_name} || |
90 |
[undef, [undef, |
91 |
($nsuri) eq \$SVG_NS ? |
92 |
(\$svg_attr_name->{\$attr_name} || \$attr_name) : |
93 |
($nsuri) eq \$MML_NS ? |
94 |
(\$attr_name eq 'definitionurl' ? |
95 |
'definitionURL' : \$attr_name) : |
96 |
\$attr_name]] |
97 |
} |
98 |
]; |
99 |
} |
100 |
$r .= qq{ |
101 |
for my \$attr_name (keys %{$attrs}) { |
102 |
my \$attr_t = $attrs\->{\$attr_name}; |
103 |
my \$attr = \$self->{document}->create_attribute_ns ($attr_xname); |
104 |
\$attr->value (\$attr_t->{value}); |
105 |
\$attr->set_user_data (manakai_source_line => \$attr_t->{line}); |
106 |
\$attr->set_user_data (manakai_source_column => \$attr_t->{column}); |
107 |
$l_var->set_attribute_node_ns (\$attr); |
108 |
} |
109 |
}; |
110 |
} |
111 |
if (defined $token_var) { |
112 |
$token_var =~ s/^\s+//; |
113 |
$token_var =~ s/\s+$//; |
114 |
$r .= qq{ |
115 |
$l_var->set_user_data (manakai_source_line => $token_var\->{line}) |
116 |
if defined $token_var\->{line}; |
117 |
$l_var->set_user_data (manakai_source_column => $token_var\->{column}) |
118 |
if defined $token_var\->{column}; |
119 |
}; |
120 |
## TODO: In future version, it should be allowed for an application |
121 |
## developer to choose whether these information should be kept |
122 |
## for tracking or not for performance by some means. |
123 |
} |
124 |
$r; |
125 |
}ge; # MUST |
126 |
s{!!!parse-error;}{q{$self->{parse_error}->();}}ge; |
127 |
s{!!!parse-error\s*\(}{ |
128 |
q{$self->{parse_error}->(level => $self->{level}->{must}, } |
129 |
}ge; |
130 |
s{!!!next-token;}{q{$token = $self->_get_next_token;}}ge; |
131 |
s{!!!back-token;}{ |
132 |
q{ |
133 |
$token->{self_closing} = $self->{self_closing}; |
134 |
unshift @{$self->{token}}, $token; |
135 |
delete $self->{self_closing}; |
136 |
} |
137 |
}ge; |
138 |
s{!!!back-token\s*\(}{q{unshift @{$self->{token}}, (}}ge; |
139 |
s{!!!cp\s*\(\s*(\S+)\s*\)\s*;}{ |
140 |
$DEBUG ? qq{ |
141 |
#print STDERR "$1, "; |
142 |
\$Whatpm::HTML::Debug::cp_pass->($1) if \$Whatpm::HTML::Debug::cp_pass; |
143 |
BEGIN { |
144 |
\$Whatpm::HTML::Debug::cp->{$1} = 1; |
145 |
} |
146 |
} : '' |
147 |
}ge; |
148 |
print; |
149 |
} |