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  import org.as2lib.regexp.node.TreeInfo;
    19  
    20  /**
    21   * {@code Both} is an object added to the tree when a character class 
    22   * has another nested class in it.
    23   * 
    24   * @author Igor Sadovskiy
    25   */
    26  
    27  class org.as2lib.regexp.node.Both extends Node {
    28  	
    29      private var lhs, rhs:Node;
    30      
    31      public function Both(lhs:Node, rhs:Node) {
    32          this.lhs = lhs;
    33          this.rhs = rhs;
    34      }
    35      
    36      public function match(matcher:Object, i:Number, seq:String):Boolean {
    37          if (i < matcher.to) {
    38  	        return ((lhs.match(matcher, i, seq) && rhs.match(matcher, i, seq))
    39  	            && next.match(matcher, matcher.last, seq));
    40          }
    41          return false;
    42      }
    43      
    44      public function study(info:TreeInfo):Boolean {
    45          var maxV:Boolean = info.maxValid;
    46          var detm:Boolean = info.deterministic;
    47  
    48          var minL:Number = info.minLength;
    49          var maxL:Number = info.maxLength;
    50          lhs.study(info);
    51  
    52          var minL2:Number = info.minLength;
    53          var maxL2:Number = info.maxLength;
    54  
    55          info.minLength = minL;
    56          info.maxLength = maxL;
    57          rhs.study(info);
    58  
    59          info.minLength = Math.min(minL2, info.minLength);
    60          info.maxLength = Math.max(maxL2, info.maxLength);
    61          info.maxValid = maxV;
    62          info.deterministic = detm;
    63  
    64          return next.study(info);
    65      }
    66  }
    67