Regexp::Parser::JavaScript - A Regexp::Parser Subclass for JavaScript Regular Expressions
use Regexp::Parser::JavaScript;
my $parser = Regexp::Parser::JavaScript->new;
my @error;
## Prepare a callback function invoked whenever an error or warning
## is raised by the parser.
$parser->onerror (sub {
my %args = @_;
my $error_message = '';
if ($args{level} eq 'w') {
$error_message .= 'Warning: ';
} else {
$error_message .= 'Error: ';
}
$error_message .= sprintf $args{type}, @{$args{args}};
$error_message .= ' (';
$error_message .= substr ${$args{valueref}},
$args{pos_start}, $args{pos_end} - $args{pos_start};
$error_message .= ')';
$error_message .= "\n";
push @error, $error_message;
});
## Parse the regular expression given as a string.
## Use |eval| to catch an exception that would be thrown if the
## regular expression contains a fatal error.
eval {
$parser->parse ($regexp_as_string);
};
if ($parser->errnum) {
## @error contains at least one fatal error.
warn @error;
} else {
## @error contains no fatal error.
warn @error;
## Now, $parser->root contains the root node of the parsed regular
## expression tree. See |perldoc Regexp::Parser| for more information.
}
The Regexp::Parser::JavaScript modules provides a subclass of the
Regexp::Parser, a regular expression parser module. The
Regexp::Parser::JavaScript module provides an implementation of the
parser for the regular expression language as defined by ECMA 376
Third Edition (the ECMAScript specification), modified for
compatibility with Web browser implementations.
Apart from this additional function, this module provides the same
interface as the one applied by the Regexp::Parser::Perl58 module.
For more information, see the Regexp::Parser::Perl58 manpage.
The Regexp::Parser::JavaScript module provides same methods as
Regexp::Parser::JavaScript. See the Regexp::Parser::Perl58 manpage.
The Regexp::Parser::JavaScript module reports same kinds of errors
as the Regexp::Parser module does to the callback function
specified by the onerror method, if any. In addition, it might
also have an additional error type: RPJSe_OCTESC.
This error is reported when an octal escape sequence is used in the regular expression. The octal escape sequence is not part of the ECMAScript specification though it is supported by Web browsers for backward compatibility.
This module requires Perl 5.10.0 or later.
This module depends on Regexp::Parser and Regexp::Parser::Perl58
modules.
The latest version of this module is available at http://suika.fam.cx/regexp/.
Regular expression visualizer http://suika.fam.cx/regexp/visualizer/input. It uses this module to parse Perl 5.8 regular expressions.
the Regexp::Parser manpage - A superclass, available from CPAN.
the Regexp::Parser::Perl58 manpage - A superclass.
CVS log: http://suika.fam.cx/regexp/lib/Regexp/Parser/JavaScript.pm,cvslog.
Bug tracking system: http://manakai.g.hatena.ne.jp/task/7/.
Wakaba <w@suika.fam.cx>.
Copyright 2008-2009 Wakaba <w@suika.fam.cx>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.