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.1 |
s{!!!parse-error;}{q{$self->{parse_error}->();}}ge; |
28 |
wakaba |
1.6 |
s{!!!parse-error\s*\(}{ |
29 |
|
|
q{$self->{parse_error}->(level => $self->{must_level}, } |
30 |
|
|
}ge; |
31 |
wakaba |
1.11 |
s{!!!insert-element-f\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{ |
32 |
wakaba |
1.7 |
{ |
33 |
|
|
my \$el; |
34 |
wakaba |
1.11 |
!!!create-element (\$el, $1, $2\->{tag_name}, $2\->{attributes}, $2); |
35 |
wakaba |
1.7 |
\$insert->(\$el); |
36 |
wakaba |
1.11 |
push \@{\$self->{open_elements}}, [\$el, (\$el_category_f->{$1}->{$2\->{tag_name}} || 0) | FOREIGN_EL]; |
37 |
wakaba |
1.7 |
} |
38 |
|
|
}}ge; |
39 |
wakaba |
1.11 |
s{!!!insert-element-t\s*\(([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{ |
40 |
wakaba |
1.1 |
{ |
41 |
|
|
my \$el; |
42 |
wakaba |
1.11 |
!!!create-element (\$el, \$HTML_NS, $1, $2, $3); |
43 |
wakaba |
1.1 |
\$insert->(\$el); |
44 |
wakaba |
1.9 |
push \@{\$self->{open_elements}}, [\$el, \$el_category->{$1} || 0]; |
45 |
wakaba |
1.1 |
} |
46 |
|
|
}}ge; |
47 |
wakaba |
1.7 |
s{!!!insert-element\s*\(([^(),]+),\s*,([^(),]+)\)\s*;}{qq{ |
48 |
|
|
{ |
49 |
|
|
my \$el; |
50 |
wakaba |
1.11 |
!!!create-element (\$el, \$HTML_NS, $1,, $2); |
51 |
wakaba |
1.7 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
52 |
wakaba |
1.9 |
push \@{\$self->{open_elements}}, [\$el, \$el_category->{$1} || 0]; |
53 |
wakaba |
1.7 |
} |
54 |
|
|
}}ge; |
55 |
|
|
s{!!!insert-element\s*\(([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{ |
56 |
|
|
{ |
57 |
|
|
my \$el; |
58 |
wakaba |
1.11 |
!!!create-element (\$el, \$HTML_NS, $1, $2, $3); |
59 |
wakaba |
1.2 |
\$self->{open_elements}->[-1]->[0]->append_child (\$el); |
60 |
wakaba |
1.9 |
push \@{\$self->{open_elements}}, [\$el, \$el_category->{$1} || 0]; |
61 |
wakaba |
1.1 |
} |
62 |
|
|
}}ge; |
63 |
wakaba |
1.11 |
s{!!!create-element\s*\(([^(),]+),([^(),]+),([^(),]+)(?:,([^(),]*)(?>,([^(),]+))?)?\)\s*;}{ |
64 |
wakaba |
1.7 |
my $l_var = $1; |
65 |
wakaba |
1.1 |
my $r = qq{ |
66 |
wakaba |
1.7 |
$l_var = \$self->{document}->create_element_ns |
67 |
wakaba |
1.11 |
($2, [undef, $3]); |
68 |
wakaba |
1.1 |
}; |
69 |
wakaba |
1.11 |
if (defined $4 and length $4) { |
70 |
wakaba |
1.1 |
$r .= qq{ |
71 |
wakaba |
1.11 |
for my \$attr_name (keys %{$4}) { |
72 |
|
|
my \$attr_t = $4\->{\$attr_name}; |
73 |
wakaba |
1.8 |
my \$attr = \$self->{document}->create_attribute_ns |
74 |
|
|
(undef, [undef, \$attr_name]); |
75 |
|
|
\$attr->value (\$attr_t->{value}); |
76 |
|
|
\$attr->set_user_data (manakai_source_line => \$attr_t->{line}); |
77 |
|
|
\$attr->set_user_data (manakai_source_column => \$attr_t->{column}); |
78 |
|
|
$l_var->set_attribute_node_ns (\$attr); |
79 |
wakaba |
1.1 |
} |
80 |
|
|
}; |
81 |
wakaba |
1.7 |
} |
82 |
wakaba |
1.11 |
if (defined $5) { |
83 |
|
|
my $token_var = $5; |
84 |
wakaba |
1.7 |
$token_var =~ s/^\s+//; |
85 |
|
|
$token_var =~ s/\s+$//; |
86 |
|
|
$r .= qq{ |
87 |
|
|
$l_var->set_user_data (manakai_source_line => $token_var\->{line}) |
88 |
|
|
if defined $token_var\->{line}; |
89 |
|
|
$l_var->set_user_data (manakai_source_column => $token_var\->{column}) |
90 |
|
|
if defined $token_var\->{column}; |
91 |
|
|
}; |
92 |
|
|
## TODO: In future version, it should be allowed for an application |
93 |
|
|
## developer to choose whether these information should be kept |
94 |
|
|
## for tracking or not for performance by some means. |
95 |
wakaba |
1.1 |
} |
96 |
|
|
$r; |
97 |
|
|
}ge; # MUST |
98 |
|
|
s{!!!next-token;}{q{$token = $self->_get_next_token;}}ge; |
99 |
wakaba |
1.10 |
s{!!!back-token;}{ |
100 |
|
|
q{ |
101 |
|
|
$token->{self_closing} = $self->{self_closing}; |
102 |
|
|
unshift @{$self->{token}}, $token; |
103 |
|
|
delete $self->{self_closing}; |
104 |
|
|
} |
105 |
|
|
}ge; |
106 |
wakaba |
1.1 |
s{!!!back-token\s*\(}{q{unshift @{$self->{token}}, (}}ge; |
107 |
wakaba |
1.4 |
s{!!!cp\s*\(\s*(\S+)\s*\)\s*;}{ |
108 |
|
|
$DEBUG ? qq{ |
109 |
wakaba |
1.5 |
#print STDERR "$1, "; |
110 |
wakaba |
1.4 |
\$Whatpm::HTML::Debug::cp_pass->($1) if \$Whatpm::HTML::Debug::cp_pass; |
111 |
|
|
BEGIN { |
112 |
|
|
\$Whatpm::HTML::Debug::cp->{$1} = 1; |
113 |
|
|
} |
114 |
|
|
} : '' |
115 |
|
|
}ge; |
116 |
wakaba |
1.1 |
print; |
117 |
|
|
} |