/[suikacvs]/markup/html/whatpm/Whatpm/mkhtmlparser.pl
Suika

Contents of /markup/html/whatpm/Whatpm/mkhtmlparser.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (hide annotations) (download)
Sat Sep 13 11:31:09 2008 UTC (16 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.14: +1 -6 lines
File MIME type: text/plain
++ whatpm/Whatpm/ChangeLog	13 Sep 2008 11:31:02 -0000
	* HTML.pm.src: Remove |{char}|, which is no longer used.
	Remove |{entity_in_attr}| and |{last_attribute_value_state}|
	and replaced by |{prev_state}|.

	* mkhtmlparser.pl: Remove |{char}| feature.
	Remove |!!!back-next-input-character;| macro.

2008-09-13  Wakaba  <wakaba@suika.fam.cx>

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24