/[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.18 - (hide annotations) (download)
Mon Sep 15 09:02:27 2008 UTC (17 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.17: +0 -3 lines
File MIME type: text/plain
++ whatpm/Whatpm/ChangeLog	15 Sep 2008 09:02:14 -0000
	* HTML.pm.src, mkhtmlparser.pl: Replace |{prev_char}|
	by |{s_kwd}| in DATA_STATE.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24