Class: CompositeSexpProcessor

Inherits:
SexpProcessor show all
Defined in:
lib/composite_sexp_processor.rb

Overview

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.

Constant Summary

Constants inherited from SexpProcessor

SexpProcessor::VERSION

Instance Attribute Summary collapse

Attributes inherited from SexpProcessor

#auto_shift_type, #context, #debug, #default_method, #env, #expected, #require_empty, #strict, #unsupported, #warn_on_default

Instance Method Summary collapse

Methods inherited from SexpProcessor

#assert_empty, #assert_type, #error_handler, expand_dirs_to_files, #in_context, #process_dummy, processors, #rewrite, rewriters, #scope

Constructor Details

#initializeCompositeSexpProcessor

:nodoc:



19
20
21
22
# File 'lib/composite_sexp_processor.rb', line 19

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

Instance Attribute Details

#processorsObject (readonly)

The list o’ processors to run.



17
18
19
# File 'lib/composite_sexp_processor.rb', line 17

def processors
  @processors
end

Instance Method Details

#<<(processor) ⇒ Object

Add a processor to the list of processors to run.

Raises:

  • (ArgumentError)


27
28
29
30
31
# File 'lib/composite_sexp_processor.rb', line 27

def << processor
  raise ArgumentError, "Can only add sexp processors" unless
    SexpProcessor === processor || processor.respond_to?(:process)
  @processors << processor
end

#on_error_in(node_type, &block) ⇒ Object



44
45
46
47
48
# File 'lib/composite_sexp_processor.rb', line 44

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

#process(exp) ⇒ Object

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



37
38
39
40
41
42
# File 'lib/composite_sexp_processor.rb', line 37

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