1 |
wakaba |
1.1 |
package WebHACC::Language::WebIDL; |
2 |
|
|
use strict; |
3 |
|
|
require WebHACC::Language::Base; |
4 |
|
|
push our @ISA, 'WebHACC::Language::Base'; |
5 |
|
|
|
6 |
|
|
sub new ($) { |
7 |
|
|
my $self = bless {}, shift; |
8 |
|
|
return $self; |
9 |
|
|
} # new |
10 |
|
|
|
11 |
|
|
sub generate_syntax_error_section ($) { |
12 |
|
|
my $self = shift; |
13 |
|
|
|
14 |
|
|
require Whatpm::WebIDL; |
15 |
|
|
|
16 |
|
|
my $out = $self->output; |
17 |
wakaba |
1.3 |
$out->start_section (role => 'parse-errors'); |
18 |
|
|
$out->start_error_list (role => 'parse-errors'); |
19 |
wakaba |
1.1 |
|
20 |
|
|
my $input = $self->input; |
21 |
|
|
my $result = $self->result; |
22 |
|
|
|
23 |
|
|
require Encode; |
24 |
|
|
my $s = $input->{is_char_string} ? $input->{s} : Encode::decode ($input->{charset} || 'utf-8', $input->{s}); ## TODO: charset |
25 |
|
|
my $parser = Whatpm::WebIDL::Parser->new; |
26 |
|
|
|
27 |
wakaba |
1.2 |
$self->{structure} = $parser->parse_char_string ($input->{s}, sub { |
28 |
|
|
$result->add_error (@_, layer => 'syntax'); |
29 |
|
|
}); |
30 |
wakaba |
1.1 |
|
31 |
wakaba |
1.3 |
$out->end_error_list (role => 'parse-errors'); |
32 |
|
|
$out->end_section; |
33 |
wakaba |
1.1 |
} # generate_parse_error_section |
34 |
|
|
|
35 |
|
|
sub generate_structure_dump_section ($) { |
36 |
|
|
my $self = shift; |
37 |
|
|
|
38 |
|
|
my $out = $self->output; |
39 |
wakaba |
1.3 |
|
40 |
|
|
$out->start_section (role => 'reformatted'); |
41 |
|
|
|
42 |
wakaba |
1.1 |
$out->start_code_block; |
43 |
|
|
$out->text ($self->{structure}->idl_text); |
44 |
|
|
$out->end_code_block; |
45 |
wakaba |
1.3 |
|
46 |
wakaba |
1.1 |
$out->end_section |
47 |
|
|
} # generate_structure_dump_section |
48 |
|
|
|
49 |
wakaba |
1.4 |
sub generate_structure_error_section ($) { |
50 |
|
|
my $self = shift; |
51 |
|
|
|
52 |
|
|
my $out = $self->output; |
53 |
|
|
|
54 |
|
|
$out->start_section (role => 'structure-errors'); |
55 |
|
|
$out->start_error_list (role => 'structure-errors'); |
56 |
|
|
|
57 |
|
|
$self->{structure}->check (sub { |
58 |
|
|
$self->result->add_error (@_, layer => 'structure'); |
59 |
|
|
}); |
60 |
|
|
|
61 |
|
|
$out->end_error_list (role => 'structure-errors'); |
62 |
|
|
$out->end_section; |
63 |
|
|
} # generate_structure_error_section |
64 |
|
|
|
65 |
wakaba |
1.1 |
1; |