1 |
=head1 NAME |
2 |
|
3 |
Regexp::Parser::JavaScript - A Regexp::Parser Subclass for JavaScript |
4 |
Regular Expressions |
5 |
|
6 |
=head1 SYNOPSIS |
7 |
|
8 |
use Regexp::Parser::JavaScript; |
9 |
|
10 |
my $parser = Regexp::Parser::JavaScript->new; |
11 |
|
12 |
my @error; |
13 |
|
14 |
## Prepare a callback function invoked whenever an error or warning |
15 |
## is raised by the parser. |
16 |
$parser->onerror (sub { |
17 |
my %args = @_; |
18 |
|
19 |
my $error_message = ''; |
20 |
if ($args{level} eq 'w') { |
21 |
$error_message .= 'Warning: '; |
22 |
} else { |
23 |
$error_message .= 'Error: '; |
24 |
} |
25 |
|
26 |
$error_message .= sprintf $args{type}, @{$args{args}}; |
27 |
|
28 |
$error_message .= ' ('; |
29 |
$error_message .= substr ${$args{valueref}}, |
30 |
$args{pos_start}, $args{pos_end} - $args{pos_start}; |
31 |
$error_message .= ')'; |
32 |
|
33 |
$error_message .= "\n"; |
34 |
|
35 |
push @error, $error_message; |
36 |
}); |
37 |
|
38 |
## Parse the regular expression given as a string. |
39 |
## Use |eval| to catch an exception that would be thrown if the |
40 |
## regular expression contains a fatal error. |
41 |
eval { |
42 |
$parser->parse ($regexp_as_string); |
43 |
}; |
44 |
|
45 |
if ($parser->errnum) { |
46 |
## @error contains at least one fatal error. |
47 |
warn @error; |
48 |
} else { |
49 |
## @error contains no fatal error. |
50 |
warn @error; |
51 |
|
52 |
## Now, $parser->root contains the root node of the parsed regular |
53 |
## expression tree. See |perldoc Regexp::Parser| for more information. |
54 |
} |
55 |
|
56 |
=head1 DESCRIPTION |
57 |
|
58 |
The C<Regexp::Parser::JavaScript> modules provides a subclass of the |
59 |
C<Regexp::Parser>, a regular expression parser module. The |
60 |
C<Regexp::Parser::JavaScript> module provides an implementation of the |
61 |
parser for the regular expression language as defined by ECMA 376 |
62 |
Third Edition (the ECMAScript specification), modified for |
63 |
compatibility with Web browser implementations. |
64 |
|
65 |
Apart from this additional function, this module provides the same |
66 |
interface as the one applied by the C<Regexp::Parser::Perl58> module. |
67 |
For more information, see L<Regexp::Parser::Perl58>. |
68 |
|
69 |
=head1 METHODS |
70 |
|
71 |
The C<Regexp::Parser::JavaScript> module provides same methods as |
72 |
C<Regexp::Parser::JavaScript>. See L<Regexp::Parser::Perl58>. |
73 |
|
74 |
=head1 ERROR TYPES |
75 |
|
76 |
The C<Regexp::Parser::JavaScript> module reports same kinds of errors |
77 |
as the C<Regexp::Parser> module does to the callback function |
78 |
specified by the C<onerror> method, if any. In addition, it might |
79 |
also have an additional error type: C<RPJSe_OCTESC>. |
80 |
|
81 |
=over 4 |
82 |
|
83 |
=item RPJSe_OCTESC |
84 |
|
85 |
This error is reported when an octal escape sequence is used in the |
86 |
regular expression. The octal escape sequence is I<not> part of the |
87 |
ECMAScript specification though it is supported by Web browsers for |
88 |
backward compatibility. |
89 |
|
90 |
=back |
91 |
|
92 |
=head1 DEPENDENCY |
93 |
|
94 |
This module requires Perl 5.10.0 or later. |
95 |
|
96 |
This module depends on C<Regexp::Parser> and C<Regexp::Parser::Perl58> |
97 |
modules. |
98 |
|
99 |
=head1 SEE ALSO |
100 |
|
101 |
The latest version of this module is available at |
102 |
L<http://suika.fam.cx/regexp/>. |
103 |
|
104 |
Regular expression visualizer |
105 |
L<http://suika.fam.cx/regexp/visualizer/input>. It uses this module |
106 |
to parse Perl 5.8 regular expressions. |
107 |
|
108 |
L<Regexp::Parser> - A superclass, available from CPAN. |
109 |
|
110 |
L<Regexp::Parser::Perl58> - A superclass. |
111 |
|
112 |
=head1 DEVELOPMENT |
113 |
|
114 |
CVS log: |
115 |
L<http://suika.fam.cx/regexp/lib/Regexp/Parser/JavaScript.pm,cvslog>. |
116 |
|
117 |
Bug tracking system: L<http://manakai.g.hatena.ne.jp/task/7/>. |
118 |
|
119 |
=head1 AUTHOR |
120 |
|
121 |
Wakaba <w@suika.fam.cx>. |
122 |
|
123 |
=head1 LICENSE |
124 |
|
125 |
Copyright 2008-2009 Wakaba <w@suika.fam.cx>. |
126 |
|
127 |
This library is free software; you can redistribute it and/or modify |
128 |
it under the same terms as Perl itself. |
129 |
|
130 |
=cut |
131 |
|
132 |
# $Date: 2009/01/13 14:15:47 $ |