/[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.7 - (hide annotations) (download)
Mon Mar 17 13:23:39 2008 UTC (16 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +51 -4 lines
File MIME type: text/plain
++ whatpm/Whatpm/ChangeLog	17 Mar 2008 13:23:31 -0000
	* HTML.pm.src: Set line/column information to element nodes.

	* mkhtmlparser.pl (!!!create-element, !!!insert-element,
	and !!!insert-element-t): Set line/column information to
	element nodes.

2008-03-17  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.7 $l_var->set_attribute_ns (undef, [undef, \$attr_name],
94 wakaba 1.1 $3 ->{\$attr_name}->{value});
95     }
96     };
97 wakaba 1.7 }
98     if (defined $4) {
99     my $token_var = $4;
100     $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     s{!!!next-token;}{q{$token = $self->_get_next_token;}}ge;
115     s{!!!back-token;}{q{unshift @{$self->{token}}, $token;}}ge;
116     s{!!!back-token\s*\(}{q{unshift @{$self->{token}}, (}}ge;
117 wakaba 1.4 s{!!!cp\s*\(\s*(\S+)\s*\)\s*;}{
118     $DEBUG ? qq{
119 wakaba 1.5 #print STDERR "$1, ";
120 wakaba 1.4 \$Whatpm::HTML::Debug::cp_pass->($1) if \$Whatpm::HTML::Debug::cp_pass;
121     BEGIN {
122     \$Whatpm::HTML::Debug::cp->{$1} = 1;
123     }
124     } : ''
125     }ge;
126 wakaba 1.1 print;
127     }

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24