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