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.Pattern;
    18  import org.as2lib.regexp.node.TreeInfo;
    19  import org.as2lib.regexp.node.Not;
    20  import org.as2lib.core.BasicClass;
    21  import org.as2lib.env.except.Exception;
    22  
    23  /**
    24   * {@code Node} is a base class for all node classes. Subclasses should 
    25   * override the match() method as appropriate. This class is an accepting 
    26   * node, so its match() always returns true.
    27   * 
    28   * @author Igor Sadovskiy
    29   */
    30   
    31  class org.as2lib.regexp.node.Node extends BasicClass {
    32  	
    33      private var next:Node;
    34      
    35      public function Node() {
    36          next = Pattern.ACCEPT;
    37      }
    38      
    39      public function dup(flag:Boolean):Node {
    40          if (flag) {
    41              return new Not(this);
    42          } else {
    43              throw new Exception("Internal error in Node dup()", this, arguments);
    44          }
    45      }
    46      
    47      /**
    48       * This method implements the classic accept node.
    49       */
    50      public function match(matcher:Object, i:Number, seq:String):Boolean {
    51          matcher.last = i;
    52          matcher.groups[0] = matcher.first;
    53          matcher.groups[1] = matcher.last;
    54          return true;
    55      }
    56      
    57      /**
    58       * This method is good for all zero length assertions.
    59       */
    60      public function study(info:TreeInfo):Boolean {
    61          if (next != null) {
    62              return next.study(info);
    63          } else {
    64              return info.deterministic;
    65          }
    66      }
    67      
    68      public function getNext(Void):Node {
    69      	return next;
    70      }
    71      
    72      public function setNext(next:Node):Void {
    73      	this.next = next;
    74      }
    75  }
    76