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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Mon Apr 30 07:41:50 2007 UTC (18 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +50 -0 lines
File MIME type: text/plain
++ whatpm/What/ChangeLog	30 Apr 2007 07:41:35 -0000
2007-04-30  Wakaba  <wakaba@suika.fam.cx>

	* HTML.pm.src: The tree construction stage is implemented.

	* mkhtmlparser.pl: New macros are added.

1 #!/usr/bin/perl
2 use strict;
3
4 my $consume_entity_file_name = 'HTML-consume-entity.src';
5
6 while (<>) {
7 s/!!!emit\b/return /;
8 s{!!!consume-entity\}}{
9 open my $consume_entity_file, '<', $consume_entity_file_name
10 or die "$0: $consume_entity_file_name: $!";
11 my $r = '';
12 while (defined (my $l = <$consume_entity_file>)) {
13 $r .= $l unless $l =~ /<javascript:/;
14 }
15 $r;
16 }e;
17 s{!!!next-input-character;}{q{
18 if (@{$self->{char}}) {
19 $self->{next_input_character} = shift @{$self->{char}};
20 } else {
21 $self->{set_next_input_character}->($self);
22 }
23 }}ge;
24 s{!!!back-next-input-character\b}{q{unshift @{$self->{char}}, }}ge;
25 s{!!!parse-error;}{q{$self->{parse_error}->();}}ge;
26 s{!!!parse-error\b}{q{$self->{parse_error}->}}ge;
27 s{!!!insert-element-t\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{
28 {
29 my \$el;
30 !!!create-element (\$el, $1, $2);
31 \$insert->(\$el);
32 push \@\$open_elements, [\$el, $1];
33 }
34 }}ge;
35 s{!!!insert-element-t\s*\(([^(),]+)\)\s*;}{qq{
36 {
37 my \$el;
38 !!!create-element (\$el, $1);
39 \$insert->(\$el);
40 push \@\$open_elements, [\$el, $1];
41 }
42 }}ge;
43 s{!!!insert-element\s*\(([^(),]+),([^(),]+)\)\s*;}{qq{
44 {
45 my \$el;
46 !!!create-element (\$el, $1, $2);
47 \$open_elements->[-1]->[0]->append_child (\$el);
48 push \@\$open_elements, [\$el, $1];
49 }
50 }}ge;
51 s{!!!insert-element\s*\(([^(),]+)\)\s*;}{qq{
52 {
53 my \$el;
54 !!!create-element (\$el, $1);
55 \$open_elements->[-1]->[0]->append_child (\$el);
56 push \@\$open_elements, [\$el, $1];
57 }
58 }}ge;
59 s{!!!create-element\s*\(([^(),]+),([^(),]+)(?:,([^(),]+))?\)\s*;}{
60 my $r = qq{
61 $1 = \$self->{document}->create_element_ns
62 (q<http://www.w3.org/1999/xhtml>, [undef, $2]);
63 };
64 if (defined $3) {
65 $r .= qq{
66 for my \$attr_name (keys %{$3}) {
67 $1->set_attribute_ns (undef, [undef, \$attr_name],
68 $3 ->{\$attr_name}->{value});
69 }
70 };
71 }
72 $r;
73 }ge; # MUST
74 s{!!!next-token;}{q{$token = $self->_get_next_token;}}ge;
75 s{!!!back-token;}{q{unshift @{$self->{token}}, $token;}}ge;
76 s{!!!back-token\s*\(}{q{unshift @{$self->{token}}, (}}ge;
77 print;
78 }

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24