| 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 |
|
|
$out->start_section (id => 'parse-errors', title => 'Parse Errors'); |
| 18 |
|
|
$out->start_tag ('dl', id => 'parse-errors-list'); |
| 19 |
|
|
|
| 20 |
|
|
my $input = $self->input; |
| 21 |
|
|
my $result = $self->result; |
| 22 |
|
|
|
| 23 |
|
|
my $onerror = sub { |
| 24 |
|
|
my (%opt) = @_; |
| 25 |
|
|
my ($type, $cls, $msg) = main::get_text ($opt{type}, $opt{level}); |
| 26 |
|
|
$out->html (qq[<dt class="$cls">] . $result->get_error_label ($input, \%opt)); |
| 27 |
|
|
$type =~ tr/ /-/; |
| 28 |
|
|
$type =~ s/\|/%7C/g; |
| 29 |
|
|
$out->html (qq[<dd class="$cls">], $result->get_error_level_label (\%opt) . $msg); |
| 30 |
|
|
$out->text (' ['); |
| 31 |
|
|
$out->link ('Description', url => '../error-description#' . $type); |
| 32 |
|
|
$out->text (']'); |
| 33 |
|
|
|
| 34 |
|
|
main::add_error ('syntax', \%opt => $result); |
| 35 |
|
|
}; |
| 36 |
|
|
|
| 37 |
|
|
require Encode; |
| 38 |
|
|
my $s = $input->{is_char_string} ? $input->{s} : Encode::decode ($input->{charset} || 'utf-8', $input->{s}); ## TODO: charset |
| 39 |
|
|
my $parser = Whatpm::WebIDL::Parser->new; |
| 40 |
|
|
|
| 41 |
|
|
$self->{structure} = $parser->parse_char_string ($input->{s}, $onerror); |
| 42 |
|
|
|
| 43 |
|
|
$out->html ('</dl></div>'); |
| 44 |
|
|
} # generate_parse_error_section |
| 45 |
|
|
|
| 46 |
|
|
sub generate_structure_dump_section ($) { |
| 47 |
|
|
my $self = shift; |
| 48 |
|
|
|
| 49 |
|
|
my $out = $self->output; |
| 50 |
|
|
|
| 51 |
|
|
$out->start_section (id => 'dump-webidl', title => 'WebIDL'); |
| 52 |
|
|
$out->start_code_block; |
| 53 |
|
|
$out->text ($self->{structure}->idl_text); |
| 54 |
|
|
$out->end_code_block; |
| 55 |
|
|
$out->end_section |
| 56 |
|
|
} # generate_structure_dump_section |
| 57 |
|
|
|
| 58 |
|
|
1; |