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 |
wakaba |
1.5 |
$self->result->layer_uncertain ('charset'); |
17 |
|
|
|
18 |
wakaba |
1.1 |
my $out = $self->output; |
19 |
wakaba |
1.3 |
$out->start_section (role => 'parse-errors'); |
20 |
|
|
$out->start_error_list (role => 'parse-errors'); |
21 |
wakaba |
1.5 |
$self->result->layer_applicable ('syntax'); |
22 |
wakaba |
1.1 |
|
23 |
|
|
my $input = $self->input; |
24 |
|
|
my $result = $self->result; |
25 |
wakaba |
1.6 |
|
26 |
|
|
$self->result->layer_uncertain ('encode') unless $input->{is_char_string}; |
27 |
wakaba |
1.1 |
|
28 |
|
|
require Encode; |
29 |
|
|
my $s = $input->{is_char_string} ? $input->{s} : Encode::decode ($input->{charset} || 'utf-8', $input->{s}); ## TODO: charset |
30 |
|
|
my $parser = Whatpm::WebIDL::Parser->new; |
31 |
|
|
|
32 |
wakaba |
1.2 |
$self->{structure} = $parser->parse_char_string ($input->{s}, sub { |
33 |
|
|
$result->add_error (@_, layer => 'syntax'); |
34 |
|
|
}); |
35 |
wakaba |
1.1 |
|
36 |
wakaba |
1.3 |
$out->end_error_list (role => 'parse-errors'); |
37 |
|
|
$out->end_section; |
38 |
wakaba |
1.1 |
} # generate_parse_error_section |
39 |
|
|
|
40 |
|
|
sub generate_structure_dump_section ($) { |
41 |
|
|
my $self = shift; |
42 |
|
|
|
43 |
|
|
my $out = $self->output; |
44 |
wakaba |
1.3 |
|
45 |
|
|
$out->start_section (role => 'reformatted'); |
46 |
|
|
|
47 |
wakaba |
1.1 |
$out->start_code_block; |
48 |
|
|
$out->text ($self->{structure}->idl_text); |
49 |
|
|
$out->end_code_block; |
50 |
wakaba |
1.3 |
|
51 |
wakaba |
1.1 |
$out->end_section |
52 |
|
|
} # generate_structure_dump_section |
53 |
|
|
|
54 |
wakaba |
1.4 |
sub generate_structure_error_section ($) { |
55 |
|
|
my $self = shift; |
56 |
|
|
|
57 |
|
|
my $out = $self->output; |
58 |
|
|
|
59 |
|
|
$out->start_section (role => 'structure-errors'); |
60 |
|
|
$out->start_error_list (role => 'structure-errors'); |
61 |
wakaba |
1.5 |
$self->result->layer_applicable ('structure'); |
62 |
wakaba |
1.4 |
|
63 |
|
|
$self->{structure}->check (sub { |
64 |
|
|
$self->result->add_error (@_, layer => 'structure'); |
65 |
|
|
}); |
66 |
|
|
|
67 |
|
|
$out->end_error_list (role => 'structure-errors'); |
68 |
|
|
$out->end_section; |
69 |
|
|
} # generate_structure_error_section |
70 |
|
|
|
71 |
wakaba |
1.1 |
1; |