1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.regexp.node.Node; 18 19 /** 20 * {@code GroupHead} saves the location where the group begins in the 21 * locals and restores them when the match is done. 22 * 23 * The matchRef is used when a reference to this group is accessed later 24 * in the expression. The locals will have a negative value in them to 25 * indicate that we do not want to unset the group if the reference 26 * doesn't match. 27 * 28 * @author Igor Sadovskiy 29 */ 30 31 class org.as2lib.regexp.node.GroupHead extends Node { 32 33 private var localIndex:Number; 34 35 public function GroupHead(localCount:Number) { 36 localIndex = localCount; 37 } 38 39 public function match(matcher:Object, i:Number, seq:String):Boolean { 40 var save:Number = matcher.locals[localIndex]; 41 matcher.locals[localIndex] = i; 42 var ret:Boolean = next.match(matcher, i, seq); 43 matcher.locals[localIndex] = save; 44 return ret; 45 } 46 47 public function matchRef(matcher:Object, i:Number, seq:String):Boolean { 48 var save:Number = matcher.locals[localIndex]; 49 matcher.locals[localIndex] = ~i; 50 var ret:Boolean = next.match(matcher, i, seq); 51 matcher.locals[localIndex] = save; 52 return ret; 53 } 54 55 public function getLocalIndex(Void):Number { 56 return localIndex; 57 } 58 } 59 60