| 1 |
wakaba |
1.1 |
<?xml version="1.0" ?> |
| 2 |
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 3 |
|
|
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 |
|
|
<head> |
| 5 |
|
|
<title>Regexp::Parser::JavaScript - A Regexp::Parser Subclass for JavaScript |
| 6 |
|
|
Regular Expressions</title> |
| 7 |
|
|
<link rel="stylesheet" href="http://suika.fam.cx/www/style/html/pod.css" type="text/css" /> |
| 8 |
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
| 9 |
|
|
<link rev="made" href="mailto:wakaba@suika.fam.cx" /> |
| 10 |
|
|
</head> |
| 11 |
|
|
|
| 12 |
|
|
<body> |
| 13 |
|
|
|
| 14 |
|
|
|
| 15 |
|
|
<!-- INDEX BEGIN --> |
| 16 |
|
|
<div name="index"> |
| 17 |
|
|
<p><a name="__index__"></a></p> |
| 18 |
|
|
|
| 19 |
|
|
<ul> |
| 20 |
|
|
|
| 21 |
|
|
<li><a href="#name">NAME</a></li> |
| 22 |
|
|
<li><a href="#synopsis">SYNOPSIS</a></li> |
| 23 |
|
|
<li><a href="#description">DESCRIPTION</a></li> |
| 24 |
|
|
<li><a href="#methods">METHODS</a></li> |
| 25 |
|
|
<li><a href="#error_types">ERROR TYPES</a></li> |
| 26 |
|
|
<li><a href="#dependency">DEPENDENCY</a></li> |
| 27 |
|
|
<li><a href="#see_also">SEE ALSO</a></li> |
| 28 |
|
|
<li><a href="#development">DEVELOPMENT</a></li> |
| 29 |
|
|
<li><a href="#author">AUTHOR</a></li> |
| 30 |
|
|
<li><a href="#license">LICENSE</a></li> |
| 31 |
|
|
</ul> |
| 32 |
|
|
|
| 33 |
|
|
<hr name="index" /> |
| 34 |
|
|
</div> |
| 35 |
|
|
<!-- INDEX END --> |
| 36 |
|
|
|
| 37 |
|
|
<p> |
| 38 |
|
|
</p> |
| 39 |
|
|
<h1><a name="name">NAME</a></h1> |
| 40 |
|
|
<p>Regexp::Parser::JavaScript - A Regexp::Parser Subclass for JavaScript |
| 41 |
|
|
Regular Expressions</p> |
| 42 |
|
|
<p> |
| 43 |
|
|
</p> |
| 44 |
|
|
<hr /> |
| 45 |
|
|
<h1><a name="synopsis">SYNOPSIS</a></h1> |
| 46 |
|
|
<pre> |
| 47 |
|
|
use Regexp::Parser::JavaScript; |
| 48 |
|
|
|
| 49 |
|
|
my $parser = Regexp::Parser::JavaScript->new; |
| 50 |
|
|
|
| 51 |
|
|
my @error; |
| 52 |
|
|
|
| 53 |
|
|
## Prepare a callback function invoked whenever an error or warning |
| 54 |
|
|
## is raised by the parser. |
| 55 |
|
|
$parser->onerror (sub { |
| 56 |
|
|
my %args = @_; |
| 57 |
|
|
|
| 58 |
|
|
my $error_message = ''; |
| 59 |
|
|
if ($args{level} eq 'w') { |
| 60 |
|
|
$error_message .= 'Warning: '; |
| 61 |
|
|
} else { |
| 62 |
|
|
$error_message .= 'Error: '; |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
|
$error_message .= sprintf $args{type}, @{$args{args}}; |
| 66 |
|
|
|
| 67 |
|
|
$error_message .= ' ('; |
| 68 |
|
|
$error_message .= substr ${$args{valueref}}, |
| 69 |
|
|
$args{pos_start}, $args{pos_end} - $args{pos_start}; |
| 70 |
|
|
$error_message .= ')'; |
| 71 |
|
|
|
| 72 |
|
|
$error_message .= "\n"; |
| 73 |
|
|
|
| 74 |
|
|
push @error, $error_message; |
| 75 |
|
|
}); |
| 76 |
|
|
|
| 77 |
|
|
## Parse the regular expression given as a string. |
| 78 |
|
|
## Use |eval| to catch an exception that would be thrown if the |
| 79 |
|
|
## regular expression contains a fatal error. |
| 80 |
|
|
eval { |
| 81 |
|
|
$parser->parse ($regexp_as_string); |
| 82 |
|
|
}; |
| 83 |
|
|
|
| 84 |
|
|
if ($parser->errnum) { |
| 85 |
|
|
## @error contains at least one fatal error. |
| 86 |
|
|
warn @error; |
| 87 |
|
|
} else { |
| 88 |
|
|
## @error contains no fatal error. |
| 89 |
|
|
warn @error; |
| 90 |
|
|
|
| 91 |
|
|
## Now, $parser->root contains the root node of the parsed regular |
| 92 |
|
|
## expression tree. See |perldoc Regexp::Parser| for more information. |
| 93 |
|
|
}</pre> |
| 94 |
|
|
<p> |
| 95 |
|
|
</p> |
| 96 |
|
|
<hr /> |
| 97 |
|
|
<h1><a name="description">DESCRIPTION</a></h1> |
| 98 |
|
|
<p>The <code>Regexp::Parser::JavaScript</code> modules provides a subclass of the |
| 99 |
|
|
<code>Regexp::Parser</code>, a regular expression parser module. The |
| 100 |
|
|
<code>Regexp::Parser::JavaScript</code> module provides an implementation of the |
| 101 |
|
|
parser for the regular expression language as defined by ECMA 376 |
| 102 |
|
|
Third Edition (the ECMAScript specification), modified for |
| 103 |
|
|
compatibility with Web browser implementations.</p> |
| 104 |
|
|
<p>Apart from this additional function, this module provides the same |
| 105 |
|
|
interface as the one applied by the <code>Regexp::Parser::Perl58</code> module. |
| 106 |
|
|
For more information, see <a href="../../Regexp/Parser/Perl58.html">the Regexp::Parser::Perl58 manpage</a>.</p> |
| 107 |
|
|
<p> |
| 108 |
|
|
</p> |
| 109 |
|
|
<hr /> |
| 110 |
|
|
<h1><a name="methods">METHODS</a></h1> |
| 111 |
|
|
<p>The <code>Regexp::Parser::JavaScript</code> module provides same methods as |
| 112 |
|
|
<code>Regexp::Parser::JavaScript</code>. See <a href="../../Regexp/Parser/Perl58.html">the Regexp::Parser::Perl58 manpage</a>.</p> |
| 113 |
|
|
<p> |
| 114 |
|
|
</p> |
| 115 |
|
|
<hr /> |
| 116 |
|
|
<h1><a name="error_types">ERROR TYPES</a></h1> |
| 117 |
|
|
<p>The <code>Regexp::Parser::JavaScript</code> module reports same kinds of errors |
| 118 |
|
|
as the <code>Regexp::Parser</code> module does to the callback function |
| 119 |
|
|
specified by the <code>onerror</code> method, if any. In addition, it might |
| 120 |
|
|
also have an additional error type: <a href="#rpjse_octesc"><code>RPJSe_OCTESC</code></a>.</p> |
| 121 |
|
|
<dl> |
| 122 |
|
|
<dt><strong><a name="rpjse_octesc" class="item">RPJSe_OCTESC</a></strong> |
| 123 |
|
|
|
| 124 |
|
|
<dd> |
| 125 |
|
|
<p>This error is reported when an octal escape sequence is used in the |
| 126 |
|
|
regular expression. The octal escape sequence is <em>not</em> part of the |
| 127 |
|
|
ECMAScript specification though it is supported by Web browsers for |
| 128 |
|
|
backward compatibility.</p> |
| 129 |
|
|
</dd> |
| 130 |
|
|
</li> |
| 131 |
|
|
</dl> |
| 132 |
|
|
<p> |
| 133 |
|
|
</p> |
| 134 |
|
|
<hr /> |
| 135 |
|
|
<h1><a name="dependency">DEPENDENCY</a></h1> |
| 136 |
|
|
<p>This module requires Perl 5.10.0 or later.</p> |
| 137 |
|
|
<p>This module depends on <code>Regexp::Parser</code> and <code>Regexp::Parser::Perl58</code> |
| 138 |
|
|
modules.</p> |
| 139 |
|
|
<p> |
| 140 |
|
|
</p> |
| 141 |
|
|
<hr /> |
| 142 |
|
|
<h1><a name="see_also">SEE ALSO</a></h1> |
| 143 |
|
|
<p>The latest version of this module is available at |
| 144 |
|
|
<a href="http://suika.fam.cx/regexp/">http://suika.fam.cx/regexp/</a>.</p> |
| 145 |
|
|
<p>Regular expression visualizer |
| 146 |
|
|
<a href="http://suika.fam.cx/regexp/visualizer/input">http://suika.fam.cx/regexp/visualizer/input</a>. It uses this module |
| 147 |
|
|
to parse Perl 5.8 regular expressions.</p> |
| 148 |
|
|
<p><a href="../../Regexp/Parser.html">the Regexp::Parser manpage</a> - A superclass, available from CPAN.</p> |
| 149 |
|
|
<p><a href="../../Regexp/Parser/Perl58.html">the Regexp::Parser::Perl58 manpage</a> - A superclass.</p> |
| 150 |
|
|
<p> |
| 151 |
|
|
</p> |
| 152 |
|
|
<hr /> |
| 153 |
|
|
<h1><a name="development">DEVELOPMENT</a></h1> |
| 154 |
|
|
<p>CVS log: |
| 155 |
|
|
<a href="http://suika.fam.cx/regexp/lib/Regexp/Parser/JavaScript.pm,cvslog">http://suika.fam.cx/regexp/lib/Regexp/Parser/JavaScript.pm,cvslog</a>.</p> |
| 156 |
|
|
<p>Bug tracking system: <a href="http://manakai.g.hatena.ne.jp/task/7/">http://manakai.g.hatena.ne.jp/task/7/</a>.</p> |
| 157 |
|
|
<p> |
| 158 |
|
|
</p> |
| 159 |
|
|
<hr /> |
| 160 |
|
|
<h1><a name="author">AUTHOR</a></h1> |
| 161 |
|
|
<p>Wakaba <<a href="mailto:w@suika.fam.cx">w@suika.fam.cx</a>>.</p> |
| 162 |
|
|
<p> |
| 163 |
|
|
</p> |
| 164 |
|
|
<hr /> |
| 165 |
|
|
<h1><a name="license">LICENSE</a></h1> |
| 166 |
|
|
<p>Copyright 2008-2009 Wakaba <<a href="mailto:w@suika.fam.cx">w@suika.fam.cx</a>>.</p> |
| 167 |
|
|
<p>This library is free software; you can redistribute it and/or modify |
| 168 |
|
|
it under the same terms as Perl itself.</p> |
| 169 |
|
|
|
| 170 |
|
|
</body> |
| 171 |
|
|
|
| 172 |
|
|
</html> |