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