001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package js.core;
021 
022 import js.ArrayLike;
023 import js.Js;
024 import js.ObjectLike;
025 import js.RegExpLike;
026 import js.StringLike;
027 import js.Value;
028 import js.Vars;
029 
030 /**
031  * <p>An <b>opaque</b> class representing JavaScript regular expression objects.</p>
032  *
033  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
034  * @see Js#re(String)
035  * @see Js#re(String, String)
036  * @see js.core.JsGlobal.RegExp#create(Object, Object)
037  * 
038  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be 
039  * generated into the target codes. Re-compilers must exit with error on the operations of 
040  * accessing that kind of class objects.
041  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored 
042  * and <tt>instanceof</tt> to it always <tt>true</tt>.
043  */
044 public class JsRegExp extends JsGlobal.RegExp.Prototype implements RegExpLike
045 {
046     /**
047      * <p>An <b>internal</b> class containing membership data for its enclosing 
048      * opaque class.</p>
049      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or 
050      * class members.</p>
051      *
052      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
053      * 
054      * @javascript Re-compilers must report error on resolving an <b>internal</b> class. 
055      */
056     protected static abstract class Members extends JsGlobal.RegExp.Prototype.Members
057     {
058         /**
059          * <p>An <b>internal</b> static field defining a member ID of the field name and 
060          * used internally to define a member of the same name.</p>
061          * @since 1.0
062          * @see JsRegExp#global
063          * @see Member#global
064          * @javascript Re-compilers must report error on accessing an <b>internal</b> field. 
065          */
066         public final static Mid global     = id("global"    );
067         /**
068          * <p>An <b>internal</b> static field defining a member ID of the field name and 
069          * used internally to define a member of the same name.</p>
070          * @since 1.0
071          * @see JsRegExp#ignoreCase
072          * @see Member#ignoreCase
073          * @javascript Re-compilers must report error on accessing an <b>internal</b> field. 
074          */
075         public final static Mid ignoreCase = id("ignoreCase");
076         /**
077          * <p>An <b>internal</b> static field defining a member ID of the field name and 
078          * used internally to define a member of the same name.</p>
079          * @since 1.0
080          * @see JsRegExp#multiline
081          * @see Member#multiline
082          * @javascript Re-compilers must report error on accessing an <b>internal</b> field. 
083          */
084         public final static Mid multiline  = id("multiline" );
085         /**
086          * <p>An <b>internal</b> static field defining a member ID of the field name and 
087          * used internally to define a member of the same name.</p>
088          * @since 1.0
089          * @see JsRegExp#lastIndex
090          * @see Member#lastIndex
091          * @javascript Re-compilers must report error on accessing an <b>internal</b> field. 
092          */
093         public final static Mid lastIndex  = id("lastIndex" );
094         /**
095          * <p>An <b>internal</b> static field defining a member ID of the field name and 
096          * used internally to define a member of the same name.</p>
097          * @since 1.0
098          * @see JsRegExp#source
099          * @see Member#source
100          * @javascript Re-compilers must report error on accessing an <b>internal</b> field. 
101          */
102         public final static Mid source     = id("source"    );
103     }
104 
105     /**
106      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
107      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
108      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
109      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
110      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
111      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
112      * either circumstance, the field names must be exactly same as the member names, as 
113      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
114      * based on the field names.</p>
115      *
116      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
117      * 
118      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created 
119      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
120      * of class objects.
121      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in 
122      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
123      * <pre>q.m</pre>
124      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier 
125      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
126      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
127      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
128      * <pre>m</pre>
129      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report 
130      * error on the access to <b>opaque</b> fields declared by this class under any other 
131      * circumstances.
132      */
133     public static class Member extends JsGlobal.RegExp.Prototype.Member
134     {
135         /**
136          * <p>Internally constructs a member based on a qualifying member.</p>
137          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
138          * or <b>internal</b> classes or class members.</p>
139          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
140          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
141          * declared in the declaring class of this constructor itself or its subclasses. 
142          * Under this circumstance, the field names must be exactly same as the member 
143          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
144          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly 
145          * to their names appending to the name resolved from the specified qualifying 
146          * member with a dot in between.</p>
147          * @param q A qualifying member
148          * @param mid The ID of the member to construct
149          * @since 1.0
150          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
151          */
152         public Member(JsObject.Member q, Mid mid) {
153             super(q, mid);
154         }
155         /**
156          * <p>Internally constructs a member without a qualifying member.</p>
157          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
158          * or <b>internal</b> classes or class members.</p>
159          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
160          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
161          * declared in <b>opaque</b> types other than the declaring class of this constructor 
162          * itself and its subclasses. Under this circumstance, the field names must be 
163          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b> 
164          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
165          * @param mid The ID of the member to construct
166          * @since 1.0
167          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
168          */
169         public Member(Mid mid) {
170             super(mid);
171         }
172         /**
173          * <p>Evaluates the property, represented by the current member instance, of the 
174          * argument object.</p>
175          * @param o The argument object
176          * @return The value of the current member based on the object argument.
177          * @since 1.0
178          * @javascript Re-compilers must convert the instance invocation of this method into 
179          * the JavaScript expression: 
180          * <pre>o.m</pre>
181          * where <tt>m</tt> is the identifier name resolved from the current member 
182          * instance of the invocation.
183          */
184         @Override
185         public JsRegExp with(ObjectLike o) {
186             return new JsRegExp(super.with(o));
187         }
188 
189         /**
190          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
191          * name of this field, qualified by the current member instance of the field, and 
192          * to access the property of the name on an object.</p>
193          * <p>The <tt>constructor</tt> property of an object is a reference to the function 
194          * that was the constructor for that object.</p>
195          * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown 
196          * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation 
197          * to determine whether it is a primitive value or an object. If it is an object, you can 
198          * use the <tt>constructor</tt> property to determine what type of object it is.</p>
199          * <p>Note, however, that while this technique works for the objects built into core 
200          * JavaScript, it is not guaranteed to work with host objects such as the <tt>window</tt> 
201          * object of client-side JavaScript. The default implementation of the <tt>toString()</tt> 
202          * method provides another way to determine the type of an unknown object.</p>
203          * @since 1.0
204          * @javascript Re-compilers must resolve the member of this instance field to the 
205          * identifier of the field name appending to the identifier resolved from its 
206          * qualifying member with a dot in between.
207          */
208         public final JsFunction.Member<JsRegExp> constructor = new JsFunction.Member<JsRegExp>(this, Members.constructor, Generic.get(JsRegExp.class));
209         /**
210          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
211          * name of this field, qualified by the current member instance of the field, and 
212          * to access the property of the name on an object.</p>
213          * @since 1.0
214          * @see JsRegExp#global()
215          * @javascript Re-compilers must resolve the member of this instance field to the 
216          * identifier of the field name appending to the identifier resolved from its 
217          * qualifying member with a dot in between.
218          */
219         public final Value.Boolean.Member global     = new Value.Boolean.Member(this, Members.global    );
220         /**
221          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
222          * name of this field, qualified by the current member instance of the field, and 
223          * to access the property of the name on an object.</p>
224          * @since 1.0
225          * @see JsRegExp#ignoreCase()
226          * @javascript Re-compilers must resolve the member of this instance field to the 
227          * identifier of the field name appending to the identifier resolved from its 
228          * qualifying member with a dot in between.
229          */
230         public final Value.Boolean.Member ignoreCase = new Value.Boolean.Member(this, Members.ignoreCase);
231         /**
232          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
233          * name of this field, qualified by the current member instance of the field, and 
234          * to access the property of the name on an object.</p>
235          * @since 1.0
236          * @see JsRegExp#multiline()
237          * @javascript Re-compilers must resolve the member of this instance field to the 
238          * identifier of the field name appending to the identifier resolved from its 
239          * qualifying member with a dot in between.
240          */
241         public final Value.Boolean.Member multiline  = new Value.Boolean.Member(this, Members.multiline );
242         /**
243          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
244          * name of this field, qualified by the current member instance of the field, and 
245          * to access the property of the name on an object.</p>
246          * @since 1.0
247          * @see JsRegExp#lastIndex()
248          * @javascript Re-compilers must resolve the member of this instance field to the 
249          * identifier of the field name appending to the identifier resolved from its 
250          * qualifying member with a dot in between.
251          */
252         public final Value.Integer.Member lastIndex  = new Value.Integer.Member(this, Members.lastIndex );
253         /**
254          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the 
255          * name of this field, qualified by the current member instance of the field, and 
256          * to access the property of the name on an object.</p>
257          * @since 1.0
258          * @see JsRegExp#source()
259          * @javascript Re-compilers must resolve the member of this instance field to the 
260          * identifier of the field name appending to the identifier resolved from its 
261          * qualifying member with a dot in between.
262          */
263         public final Value.String .Member source     = new Value.String .Member(this, Members.source    );
264     }
265 
266     /**
267      * <p>Internally constructs a regular expression object.</p>
268      * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> or 
269      * <b>internal</b> classes or class members.</p>
270      * @since 1.0
271      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
272      */
273     protected JsRegExp(Object var) {
274         super((JsObject)var);
275     }
276     /**
277      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it 
278      * with the wrapping constructor.</p>
279      * @param var The argument of an <b>opaque</b> object.
280      * @since 1.0
281      * @javascript Re-compilers must ignore the construction operation of this constructor, 
282      * that is, replacing it with its only argument.
283      */
284     public JsRegExp(JsObject var) {
285         super(var(var, (JsRegExp)null));
286     }
287     /**
288      * <p>Constructs a regular expression object with the specified pattern.</p>
289      * @param regex A string that specifies the pattern of the regular expression.
290      * @throws RuntimeException JavaScript throws a <tt>SyntaxError</tt> If <tt>regex</tt> 
291      * is not a legal regular expression. See {@link Js#err(Object)} and {@link js.core.JsSyntaxError} 
292      * for JS Simulation.
293      * @see #JsRegExp(String, String)
294      * @see js.Js#re(String)
295      * @see js.core.JsGlobal.RegExp#create(Object)
296      * @see js.core.JsGlobal.RegExp#create(Vars)
297      * @see js.core.JsGlobal.RegExp#invoke(Object)
298      * @see js.core.JsGlobal.RegExp#invoke(Vars)
299      * @since 1.0
300      * @javascript Re-compilers must replace the construction operation of this constructor 
301      * with the JavaScript expression:
302      * <pre>new RegExp(regex)</pre>
303      */
304     public JsRegExp(String regex) {
305         this(JsGlobal.RegExp.with().create(regex));
306     }
307     /**
308      * <p>Constructs a regular expression object with the specified pattern and flags.</p>
309      * @param regex A string that specifies the pattern of the regular expression.
310      * @param flags An optional string containing any of the "g", "i", and "m" attributes 
311      * that specify global, case-insensitive, and multiline matches, respectively. The "m" 
312      * attribute is not available prior to ECMAScript standardization.
313      * @throws RuntimeException JavaScript throws a <tt>SyntaxError</tt> If <tt>regex</tt> 
314      * is not a legal regular expression, or if <tt>flags</tt> contains characters other than 
315      * "g", "i", and "m". See {@link Js#err(Object)} and {@link js.core.JsSyntaxError} for 
316      * JS Simulation.
317      * @see #JsRegExp(String)
318      * @see js.Js#re(String, String)
319      * @see js.core.JsGlobal.RegExp#create(Object, Object)
320      * @see js.core.JsGlobal.RegExp#create(Vars)
321      * @see js.core.JsGlobal.RegExp#invoke(Object, Object)
322      * @see js.core.JsGlobal.RegExp#invoke(Vars)
323      * @since 1.0
324      * @javascript Re-compilers must replace the construction operation of this constructor 
325      * with the JavaScript expression:
326      * <pre>new RegExp(regex, flags)</pre>
327      */
328     public JsRegExp(String regex, String flags) {
329         this(JsGlobal.RegExp.with().create(regex, flags));
330     }
331 
332     /**
333      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
334      * without a qualifying member and to access the property of the name on an object.</p>
335      * <p>The <tt>constructor</tt> property of an object is a reference to the function 
336      * that was the constructor for that object.</p>
337      * <p>A common use of the <tt>constructor</tt> property is to determine the type of unknown 
338      * objects. Given an unknown value, you can use the {@link js.Js#typeof(Object)} operation 
339      * to determine whether it is a primitive value or an object. If it is an object, you can 
340      * use the <tt>constructor</tt> property to determine what type of object it is.</p>
341      * <p>Note, however, that while this technique works for the objects built into core 
342      * JavaScript, it is not guaranteed to work with host objects such as the <tt>window</tt> 
343      * object of client-side JavaScript. The default implementation of the <tt>toString()</tt> 
344      * method provides another way to determine the type of an unknown object.</p>
345      * @since 1.0
346      * @javascript Re-compilers must resolve the member of this static field to the 
347      * identifier of the field name.
348      */
349     public static final JsFunction.Member<JsRegExp> constructor = new JsFunction.Member<JsRegExp>(Members.constructor, Generic.get(JsRegExp.class));
350     /**
351      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
352      * without a qualifying member and to access the property of the name on an object.</p>
353      * @see JsRegExp#global()
354      * @since 1.0
355      * @javascript Re-compilers must resolve the member of this static field to the 
356      * identifier of the field name.
357      */
358     public static final Value.Boolean.Member global     = new Value.Boolean.Member(Members.global    );
359     /**
360      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
361      * without a qualifying member and to access the property of the name on an object.</p>
362      * @since 1.0
363      * @see JsRegExp#ignoreCase()
364      * @javascript Re-compilers must resolve the member of this static field to the 
365      * identifier of the field name.
366      */
367     public static final Value.Boolean.Member ignoreCase = new Value.Boolean.Member(Members.ignoreCase);
368     /**
369      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
370      * without a qualifying member and to access the property of the name on an object.</p>
371      * @since 1.0
372      * @see JsRegExp#multiline()
373      * @javascript Re-compilers must resolve the member of this static field to the 
374      * identifier of the field name.
375      */
376     public static final Value.Boolean.Member multiline  = new Value.Boolean.Member(Members.multiline );
377     /**
378      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
379      * without a qualifying member and to access the property of the name on an object.</p>
380      * @since 1.0
381      * @see JsRegExp#lastIndex()
382      * @javascript Re-compilers must resolve the member of this static field to the 
383      * identifier of the field name.
384      */
385     public static final Value.Integer.Member lastIndex  = new Value.Integer.Member(Members.lastIndex );
386     /**
387      * <p>An <b>opaque</b> static field defining a member that is named by the field name 
388      * without a qualifying member and to access the property of the name on an object.</p>
389      * @since 1.0
390      * @see JsRegExp#source()
391      * @javascript Re-compilers must resolve the member of this static field to the 
392      * identifier of the field name.
393      */
394     public static final Value.String .Member source     = new Value.String .Member(Members.source    );
395 
396     /**
397      * <p>Gets the <tt>global</tt> field of the current regular expression instance.</p>
398      * <p>The <tt>global</tt> field is a read-only boolean property of regular expression
399      * instances. It specifies whether a particular regular expression performs global matching, 
400      * that is, whether it was created with the "g" attribute.</p>
401      * @return The value of the <tt>global</tt> field of the regular expression.
402      * @see Js#re(String, String)
403      * @since 1.0
404      * @javascript Re-compilers must convert the instance invocation of this method into the 
405      * JavaScript expression: 
406      * <pre>re.global</pre>
407      * where <tt>re</tt> is the current regular expression instance of the invocation.
408      */
409     public final boolean global() {
410         return Js.be(global.with(this));
411     }
412     /**
413      * <p>Gets the <tt>ignoreCase</tt> field of the current regular expression instance.</p>
414      * <p>The <tt>ignoreCase</tt> field is a read-only boolean property of regular expression 
415      * instances. It specifies whether a particular regular expression performs case-insensitive 
416      * matching, that is, whether it was created with the "i" attribute.</p>
417      * @return The value of the <tt>ignoreCase</tt> field of the regular expression.
418      * @see Js#re(String, String)
419      * @since 1.0
420      * @javascript Re-compilers must convert the instance invocation of this method into the 
421      * JavaScript expression: 
422      * <pre>re.ignoreCase</pre>
423      * where <tt>re</tt> is the current regular expression instance of the invocation.
424      */
425     public final boolean ignoreCase() {
426         return Js.be(ignoreCase.with(this));
427     }
428     /**
429      * <p>Gets the <tt>multiline</tt> field of the current regular expression instance.</p>
430      * <p>The <tt>multiline</tt> field is a read-only boolean property of regular expression 
431      * instances. It specifies whether a particular regular expression performs multiline 
432      * matching, that is, whether it was created with the "m" attribute.</p>
433      * @return The value of the <tt>multiline</tt> field of the regular expression.
434      * @see Js#re(String, String)
435      * @since 1.0
436      * @javascript Re-compilers must convert the instance invocation of this method into the 
437      * JavaScript expression: 
438      * <pre>re.multiline</pre>
439      * where <tt>re</tt> is the current regular expression instance of the invocation.
440      */
441     public final boolean multiline() {
442         return Js.be(multiline.with(this));
443     }
444     /**
445      * <p>Gets the <tt>lastIndex</tt> field of the current regular expression instance.</p>
446      * <p>The <tt>lastIndex</tt> field is a read/write property of regular expression 
447      * instances. For regular expressions with the "g" attribute set, it contains an 
448      * integer that specifies the character position immediately following the last match 
449      * found by the {@link #exec(Object)} and {@link #test(Object)} methods. These methods 
450      * use this property as the starting point for the next search they conduct. This 
451      * allows you to call those methods repeatedly, to loop through all matches in a 
452      * string. Note that <tt>lastIndex</tt> is not used by regular expressions that do 
453      * not have the "g" attribute set and do not represent global patterns.</p>
454      * <p>This property is read/write, so you can set it at any time to specify where in the 
455      * target string the next search should begin. {@link #exec(Object)} and {@link #test(Object)} 
456      * automatically reset <tt>lastIndex</tt> to 0 when they fail to find a match 
457      * (or another match). If you begin to search a new string after a successful match 
458      * of some other string, you have to explicitly set this property to 0.</p>
459      * @return The value of the <tt>lastIndex</tt> field of the regular expression.
460      * @see #lastIndex(Integer)
461      * @see #exec(Object)
462      * @see #test(Object)
463      * @since 1.0
464      * @javascript Re-compilers must convert the instance invocation of this method into the 
465      * JavaScript expression: 
466      * <pre>re.lastIndex</pre>
467      * where <tt>re</tt> is the current regular expression instance of the invocation.
468      */
469     public final Integer lastIndex() {
470         return lastIndex.with(this);
471     }
472     /**
473      * <p>Sets the <tt>lastIndex</tt> field of the current regular expression instance.</p>
474      * <p>The <tt>lastIndex</tt> field is a read/write property of regular expression 
475      * instances. For regular expressions with the "g" attribute set, it contains an 
476      * integer that specifies the character position immediately following the last match 
477      * found by the {@link #exec(Object)} and {@link #test(Object)} methods. These methods 
478      * use this property as the starting point for the next search they conduct. This 
479      * allows you to call those methods repeatedly, to loop through all matches in a 
480      * string. Note that <tt>lastIndex</tt> is not used by regular expressions that do 
481      * not have the "g" attribute set and do not represent global patterns.</p>
482      * <p>This property is read/write, so you can set it at any time to specify where in the 
483      * target string the next search should begin. {@link #exec(Object)} and {@link #test(Object)} 
484      * automatically reset <tt>lastIndex</tt> to 0 when they fail to find a match 
485      * (or another match). If you begin to search a new string after a successful match 
486      * of some other string, you have to explicitly set this property to 0.</p>
487      * @return The new value of the <tt>lastIndex</tt>.
488      * @see #lastIndex()
489      * @see #exec(Object)
490      * @see #test(Object)
491      * @since 1.0
492      * @javascript Re-compilers must convert the instance invocation of this method into the 
493      * JavaScript expression: 
494      * <pre>(re.lastIndex=lastIndex)</pre>
495      * where <tt>re</tt> is the current regular expression instance of the invocation.
496      */
497     public final Integer lastIndex(Integer lastIndex) {
498         return var(JsRegExp.lastIndex, lastIndex);
499     }
500     /**
501      * <p>Gets the <tt>source</tt> field of the current regular expression instance.</p>
502      * <p>The <tt>source</tt> field is a read-only string property of regular expression 
503      * instances. It contains the text of the regular expression. This text does not include 
504      * the delimiting slashes used in regular-expression literals, and it does not include 
505      * the "g", "i", and "m" attributes.</p>
506      * @return The source text of the regular expression.
507      * @since 1.0
508      * @javascript Re-compilers must convert the instance invocation of this method into the 
509      * JavaScript expression: 
510      * <pre>re.source</pre>
511      * where <tt>re</tt> is the current regular expression instance of the invocation.
512      */
513     public final String source() {
514         return source.with(this);
515     }
516     /**
517      * <p>Performs powerful, general-purpose pattern matching with the current regular expression instance.</p>
518      * <p>This method is the most powerful of all the regular expression and string 
519      * pattern-matching methods. It is a general-purpose method that is somewhat more 
520      * complex to use than {@link #test(Object)}, {@link StringLike#search(RegExpLike)}, 
521      * {@link StringLike#replace(RegExpLike, String)}, and {@link StringLike#match(RegExpLike)}.</p>
522      * <p>This invocation searches string for text that matches the current regular expression. 
523      * If it finds a match, it returns an array of results; otherwise, it returns 
524      * <tt>null</tt>. Element 0 of the returned array is the matched text. Element 1 is 
525      * the text that matched the first parenthesized subexpression, if any, within the current 
526      * regular expression. Element 2 contains the text that matched the second subexpression, 
527      * and so on. The array length property specifies the number of elements in the array, 
528      * as usual. In addition to the array elements and the length property, the value 
529      * returned by the invocation also has two other properties. The <tt>index</tt> 
530      * property (see {@link ArrayLike#index()}) specifies the character position of the first 
531      * character of the matched text. The <tt>input</tt> property (see {@link ArrayLike#input()}) 
532      * refers to <tt>s</tt>. This returned array is the same as the array that is 
533      * returned by the {@link StringLike#match(RegExpLike)} method, when invoked on a 
534      * non-global regular expression instance.</p>
535      * <p>When this method is invoked on a non-global pattern, it performs the search and 
536      * returns the result described earlier. When the current instance is a global regular 
537      * expression, however, the invocation behaves in a slightly more complex way. It begins 
538      * searching string at the character position specified by the <tt>lastIndex</tt> 
539      * property (see {@link #lastIndex()} and {@link #lastIndex(Integer)}) of the current 
540      * regular expression. When it finds a match, it sets <tt>lastIndex</tt> to the 
541      * position of the first character after the match. This means that you can invoke 
542      * this method repeatedly in order to loop through all matches in a string. When 
543      * the invocation cannot find any more matches, it returns <tt>null</tt> and 
544      * resets <tt>lastIndex</tt> to zero. If you begin searching a new string 
545      * immediately after successfully finding a match in another string, you must be 
546      * careful to manually reset <tt>lastIndex</tt> to zero.</p>
547      * <p>Note that this invocation always includes full details of every match in the 
548      * array it returns, whether or not the current regular expression is a global pattern. 
549      * This is where this method differs from {@link StringLike#match(RegExpLike)}, which 
550      * returns much less information when used with global patterns. Calling this method 
551      * repeatedly in a loop is the only way to obtain complete pattern-matching 
552      * information for a global pattern.</p>
553      * @param s The string to be tested.
554      * @return An array containing the results of the match or undefined 
555      * <tt>null</tt> if no match was found.
556      * @throws RuntimeException JavaScript throws a <tt>TypeError</tt> if this method 
557      * is invoked with an instance that is not a regular expression. See {@link Js#err(Object)} 
558      * and {@link js.core.JsTypeError} for JS Simulation.
559      * @see #lastIndex()
560      * @see #lastIndex(Integer)
561      * @see #test(Object)
562      * @see StringLike#match(RegExpLike)
563      * @see StringLike#replace(RegExpLike, String)
564      * @see StringLike#replace(RegExpLike, StringLike)
565      * @see StringLike#replace(RegExpLike, js.core.JsFunction)
566      * @see StringLike#search(RegExpLike)
567      * @since 1.0
568      * @javascript Re-compilers must convert the instance invocation of this method directly 
569      * into a JavaScript invocation on its current regular expression instance without changing the 
570      * method name, but expanding variable arguments, if any, into comma-separated values. 
571      */
572     public final JsArray exec(Object s) {
573         return new JsArray(call(exec, s));
574     }
575     /**
576      * <p>Tests whether a string contains the pattern represented by the current regular 
577      * expression.</p>
578      * <p></p>
579      * @param s The string to be tested.
580      * @return <tt>true</tt> if <tt>s</tt> contains text that matches the current 
581      * regular expression; false otherwise.
582      * @throws RuntimeException JavaScript throws a <tt>TypeError</tt> if this method 
583      * is invoked with an instance that is not a regular expression. See {@link Js#err(Object)} 
584      * and {@link js.core.JsTypeError} for JS Simulation.
585      * @see #exec(Object)
586      * @see #lastIndex()
587      * @see #lastIndex(Integer)
588      * @see StringLike#match(RegExpLike)
589      * @see StringLike#replace(RegExpLike, String)
590      * @see StringLike#replace(RegExpLike, StringLike)
591      * @see StringLike#replace(RegExpLike, js.core.JsFunction)
592      * @see StringLike#search(RegExpLike)
593      * @see StringLike#substring(Object)
594      * @see StringLike#substring(Object, Object)
595      * @since 1.0
596      * @javascript Re-compilers must convert the instance invocation of this method directly 
597      * into a JavaScript invocation on its current regular expression instance without changing the 
598      * method name, but expanding variable arguments, if any, into comma-separated values. 
599      */
600     public final boolean test(Object s) {
601         return call(test, s);
602     }
603 
604     /**
605      * <p>Simply returns the current object instance.</p>
606      * <p>This method is useful for JS Simulation to implement opaque types.</p>
607      * @return The current regular expression instance.
608      * @since 1.0
609      * @javascript Re-compilers must ignore the instance invocation of this method, that is, 
610      * replacing it with its current instance.
611      */
612     @Override
613     public JsRegExp var() {
614         return (JsRegExp)super.var();
615     }
616     /**
617      * <p>Assigns the value of another object instance to the current object.</p>
618      * @param var The argument object instance.
619      * @return The new instance.
620      * @since 1.0
621      * @javascript Re-compilers must convert the instance invocation of this method into 
622      * the JavaScript expression: 
623      * <pre>o = var</pre>
624      * where <tt>o</tt> is the current instance of the invocation of this method.
625      */
626     @Override
627     public final <S extends JsObject> S var(S var) {
628         var(var, (JsRegExp)null);
629         return var;
630     }
631     /**
632      * <p>Returns the primitive value associated with the current instance, if there is one. 
633      * This invocation simply returns the instance itself for the current instance is an 
634      * object and there is no primitive value for it.</p>
635      * @return The current regular expression itself.
636      * @since 1.0
637      * @javascript Re-compilers must convert the instance invocation of this method directly 
638      * into a JavaScript invocation on its current regular expression instance without changing the 
639      * method name, but expanding variable arguments, if any, into comma-separated values. 
640      */
641     @Override
642     public JsRegExp valueOf() {
643         return new JsRegExp((JsObject)var().valueOf());
644     }
645 }