Sha256: d37465c2002267302d59211d82e02136d586bfd8080ea6bff9eaf7ce9cc9829f

Contents?: true

Size: 1.09 KB

Versions: 21

Compression:

Stored size: 1.09 KB

Contents

require 'sexp_processor'

##
# Implements the Composite pattern on SexpProcessor. Need we say more?
#
# Yeah... probably. Implements a SexpProcessor of SexpProcessors so
# you can easily chain multiple to each other. At some stage we plan
# on having all of them run +process+ and but only ever output
# something when +generate+ is called, allowing for deferred final
# processing.

class CompositeSexpProcessor < SexpProcessor

  ##
  # The list o' processors to run.

  attr_reader :processors

  def initialize # :nodoc:
    super
    @processors = []
  end

  ##
  # Add a +processor+ to the list of processors to run.

  def <<(processor)
    raise ArgumentError, "Can only add sexp processors" unless
      SexpProcessor === processor
    @processors << processor
  end

  ##
  # Run +exp+ through all of the processors, returning the final
  # result.

  def process(exp)
    @processors.each do |processor|
      exp = processor.process(exp)
    end
    exp
  end

  def on_error_in(node_type, &block)
    @processors.each do |processor|
      processor.on_error_in(node_type, &block)
    end
  end
end

Version data entries

21 entries across 19 versions & 2 rubygems

Version Path
ParseTree-1.5.0 lib/composite_sexp_processor.rb
ParseTree-1.4.1 lib/composite_sexp_processor.rb
ParseTree-1.4.0 lib/composite_sexp_processor.rb
ParseTree-1.6.2 lib/composite_sexp_processor.rb
ParseTree-1.7.0 lib/composite_sexp_processor.rb
ParseTree-1.6.3 lib/composite_sexp_processor.rb
ParseTree-1.6.4 lib/composite_sexp_processor.rb
ParseTree-1.6.0 lib/composite_sexp_processor.rb
ParseTree-1.3.7 lib/composite_sexp_processor.rb
ParseTree-1.6.1 lib/composite_sexp_processor.rb
ParseTree-1.7.1 lib/composite_sexp_processor.rb
ParseTree-2.1.1 lib/composite_sexp_processor.rb
ParseTree-2.1.0 lib/composite_sexp_processor.rb
ParseTree-2.0.1 lib/composite_sexp_processor.rb
ParseTree-2.0.2 lib/composite_sexp_processor.rb
ParseTree-2.0.0 lib/composite_sexp_processor.rb
ParseTree-2.2.0 lib/composite_sexp_processor.rb
rubyjs-0.7.1 vendor/ParseTree-1.7.1/lib/composite_sexp_processor.rb
rubyjs-0.7.0 vendor/ParseTree-1.7.1-patched/lib/composite_sexp_processor.rb
rubyjs-0.7.0 vendor/ParseTree-1.7.1/lib/composite_sexp_processor.rb