Sha256: 6b2b43dff341cde32c1a1c2741ec3210b268bf0e2b3b5647ce85e8f9df9ad1fb

Contents?: true

Size: 892 Bytes

Versions: 1

Compression:

Stored size: 892 Bytes

Contents

=begin
Copyright 2011 Shane Brinkman-Davis
See README for licence information.
http://babel-bridge.rubyforge.org/
=end

module BabelBridge
# rule node
# subclassed automatically by parser.rule for each unique non-terminal
class NonTerminalNode < Node

  def trailing_whitespace_range
    if matches.length == 0
      preceding_whitespace_range || (0..-1)
    else
      matches[-1].trailing_whitespace_range
    end
  end

  def update_match_length
    m = matches[-1]
    @match_length = m ? m.offset_after_match - offset : 0
  end

  #*****************************
  # Array interface implementation
  #*****************************
  def matches
    @matches ||= []
  end

  include Enumerable
  def length
    matches.length
  end

  def <<(node)
    matches<<node
    update_match_length
  end

  def [](i)
    matches[i]
  end

  def each(&block)
    matches.each(&block)
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
babel_bridge-0.4.0 lib/nodes/non_terminal_node.rb