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 |
|
|
## NOTE: "Adjust SVG attributes" (SVG only) and |
78 |
|
|
## "adjust foreign attributes". |
79 |
|
|
$attr_xname = qq[ |
80 |
|
|
\@{ |
81 |
|
|
\$foreign_attr_xname->{\$attr_name} || |
82 |
|
|
[undef, [undef, |
83 |
|
|
$nsuri eq \$SVG_NS ? |
84 |
|
|
(\$svg_attr_name->{\$attr_name} || \$attr_name) : |
85 |
|
|
\$attr_name]] |
86 |
|
|
} |
87 |
|
|
]; |
88 |
|
|
} |
89 |
wakaba |
1.1 |
$r .= qq{ |
90 |
wakaba |
1.12 |
for my \$attr_name (keys %{$attrs}) { |
91 |
|
|
my \$attr_t = $attrs\->{\$attr_name}; |
92 |
|
|
my \$attr = \$self->{document}->create_attribute_ns ($attr_xname); |
93 |
wakaba |
1.8 |
\$attr->value (\$attr_t->{value}); |
94 |
|
|
\$attr->set_user_data (manakai_source_line => \$attr_t->{line}); |
95 |
|
|
\$attr->set_user_data (manakai_source_column => \$attr_t->{column}); |
96 |
|
|
$l_var->set_attribute_node_ns (\$attr); |
97 |
wakaba |
1.1 |
} |
98 |
|
|
}; |
99 |
wakaba |
1.7 |
} |
100 |
wakaba |
1.12 |
if (defined $token_var) { |
101 |
wakaba |
1.7 |
$token_var =~ s/^\s+//; |
102 |
|
|
$token_var =~ s/\s+$//; |
103 |
|
|
$r .= qq{ |
104 |
|
|
$l_var->set_user_data (manakai_source_line => $token_var\->{line}) |
105 |
|
|
if defined $token_var\->{line}; |
106 |
|
|
$l_var->set_user_data (manakai_source_column => $token_var\->{column}) |
107 |
|
|
if defined $token_var\->{column}; |
108 |
|
|
}; |
109 |
|
|
## TODO: In future version, it should be allowed for an application |
110 |
|
|
## developer to choose whether these information should be kept |
111 |
|
|
## for tracking or not for performance by some means. |
112 |
wakaba |
1.1 |
} |
113 |
|
|
$r; |
114 |
|
|
}ge; # MUST |
115 |
wakaba |
1.12 |
s{!!!parse-error;}{q{$self->{parse_error}->();}}ge; |
116 |
|
|
s{!!!parse-error\s*\(}{ |
117 |
|
|
q{$self->{parse_error}->(level => $self->{must_level}, } |
118 |
|
|
}ge; |
119 |
wakaba |
1.1 |
s{!!!next-token;}{q{$token = $self->_get_next_token;}}ge; |
120 |
wakaba |
1.10 |
s{!!!back-token;}{ |
121 |
|
|
q{ |
122 |
|
|
$token->{self_closing} = $self->{self_closing}; |
123 |
|
|
unshift @{$self->{token}}, $token; |
124 |
|
|
delete $self->{self_closing}; |
125 |
|
|
} |
126 |
|
|
}ge; |
127 |
wakaba |
1.1 |
s{!!!back-token\s*\(}{q{unshift @{$self->{token}}, (}}ge; |
128 |
wakaba |
1.4 |
s{!!!cp\s*\(\s*(\S+)\s*\)\s*;}{ |
129 |
|
|
$DEBUG ? qq{ |
130 |
wakaba |
1.5 |
#print STDERR "$1, "; |
131 |
wakaba |
1.4 |
\$Whatpm::HTML::Debug::cp_pass->($1) if \$Whatpm::HTML::Debug::cp_pass; |
132 |
|
|
BEGIN { |
133 |
|
|
\$Whatpm::HTML::Debug::cp->{$1} = 1; |
134 |
|
|
} |
135 |
|
|
} : '' |
136 |
|
|
}ge; |
137 |
wakaba |
1.1 |
print; |
138 |
|
|
} |