/[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.8 - (hide annotations) (download)
Thu Mar 20 03:37:19 2008 UTC (16 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.7: +7 -2 lines
File MIME type: text/plain
++ whatpm/Whatpm/ChangeLog	20 Mar 2008 03:37:11 -0000
	* HTML.pm.src: Set line/column numbers to attributes.

	* NanoDOM.pm (create_attribute_ns, set_attribute_node_ns): Added.
	(value): Setter implemented.

	* mkhtmlparser.pl: Set line/column numbers to Attr nodes.

2008-03-20  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     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     s{!!!parse-error;}{q{$self->{parse_error}->();}}ge;
17 wakaba 1.6 s{!!!parse-error\s*\(}{
18     q{$self->{parse_error}->(level => $self->{must_level}, }
19     }ge;
20 wakaba 1.7 s{!!!insert-element-t\s*\(([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{
21     {
22     my \$el;
23     !!!create-element (\$el, $1, $2, $3);
24     \$insert->(\$el);
25     push \@{\$self->{open_elements}}, [\$el, $1];
26     }
27     }}ge;
28     s{!!!insert-element-t\s*\(([^(),]+),\s*,([^(),]+)\)\s*;}{qq{
29     {
30     my \$el;
31     !!!create-element (\$el, $1,, $2);
32     \$insert->(\$el);
33     push \@{\$self->{open_elements}}, [\$el, $1];
34     }
35     }}ge;
36 wakaba 1.1 s{!!!insert-element-t\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{
37     {
38     my \$el;
39     !!!create-element (\$el, $1, $2);
40     \$insert->(\$el);
41 wakaba 1.2 push \@{\$self->{open_elements}}, [\$el, $1];
42 wakaba 1.1 }
43     }}ge;
44     s{!!!insert-element-t\s*\(([^(),]+)\)\s*;}{qq{
45     {
46     my \$el;
47     !!!create-element (\$el, $1);
48     \$insert->(\$el);
49 wakaba 1.2 push \@{\$self->{open_elements}}, [\$el, $1];
50 wakaba 1.1 }
51     }}ge;
52 wakaba 1.7 s{!!!insert-element\s*\(([^(),]+),\s*,([^(),]+)\)\s*;}{qq{
53     {
54     my \$el;
55     !!!create-element (\$el, $1,, $2);
56     \$self->{open_elements}->[-1]->[0]->append_child (\$el);
57     push \@{\$self->{open_elements}}, [\$el, $1];
58     }
59     }}ge;
60     s{!!!insert-element\s*\(([^(),]+),([^(),]+),([^(),]+)\)\s*;}{qq{
61     {
62     my \$el;
63     !!!create-element (\$el, $1, $2, $3);
64     \$self->{open_elements}->[-1]->[0]->append_child (\$el);
65     push \@{\$self->{open_elements}}, [\$el, $1];
66     }
67     }}ge;
68 wakaba 1.1 s{!!!insert-element\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{
69     {
70     my \$el;
71     !!!create-element (\$el, $1, $2);
72 wakaba 1.2 \$self->{open_elements}->[-1]->[0]->append_child (\$el);
73     push \@{\$self->{open_elements}}, [\$el, $1];
74 wakaba 1.1 }
75     }}ge;
76     s{!!!insert-element\s*\(([^(),]+)\)\s*;}{qq{
77     {
78     my \$el;
79     !!!create-element (\$el, $1);
80 wakaba 1.2 \$self->{open_elements}->[-1]->[0]->append_child (\$el);
81     push \@{\$self->{open_elements}}, [\$el, $1];
82 wakaba 1.1 }
83     }}ge;
84 wakaba 1.7 s{!!!create-element\s*\(([^(),]+),([^(),]+)(?:,([^(),]*)(?>,([^(),]+))?)?\)\s*;}{
85     my $l_var = $1;
86 wakaba 1.1 my $r = qq{
87 wakaba 1.7 $l_var = \$self->{document}->create_element_ns
88 wakaba 1.1 (q<http://www.w3.org/1999/xhtml>, [undef, $2]);
89     };
90 wakaba 1.7 if (defined $3 and length $3) {
91 wakaba 1.1 $r .= qq{
92     for my \$attr_name (keys %{$3}) {
93 wakaba 1.8 my \$attr_t = $3\->{\$attr_name};
94     my \$attr = \$self->{document}->create_attribute_ns
95     (undef, [undef, \$attr_name]);
96     \$attr->value (\$attr_t->{value});
97     \$attr->set_user_data (manakai_source_line => \$attr_t->{line});
98     \$attr->set_user_data (manakai_source_column => \$attr_t->{column});
99     $l_var->set_attribute_node_ns (\$attr);
100 wakaba 1.1 }
101     };
102 wakaba 1.7 }
103     if (defined $4) {
104     my $token_var = $4;
105     $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     s{!!!next-token;}{q{$token = $self->_get_next_token;}}ge;
120     s{!!!back-token;}{q{unshift @{$self->{token}}, $token;}}ge;
121     s{!!!back-token\s*\(}{q{unshift @{$self->{token}}, (}}ge;
122 wakaba 1.4 s{!!!cp\s*\(\s*(\S+)\s*\)\s*;}{
123     $DEBUG ? qq{
124 wakaba 1.5 #print STDERR "$1, ";
125 wakaba 1.4 \$Whatpm::HTML::Debug::cp_pass->($1) if \$Whatpm::HTML::Debug::cp_pass;
126     BEGIN {
127     \$Whatpm::HTML::Debug::cp->{$1} = 1;
128     }
129     } : ''
130     }ge;
131 wakaba 1.1 print;
132     }

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24