The Processor class
Prev | Chapter 3. Scripting And Extending Synopsis | Next

## The Processor class

The Processor class is at the core of the Synopsis framework. It is the basic building block out of which processing pipelines can be composed.

The requirement that processors can be composed into a pipeline has some important consequences for its design. The process method takes an `ir` argument, which it will operate on, and then return. It is this `ir` that forms the backbone of the pipeline, as it is passed along from one processor to the next. Additionally, parameters may be passed to the processor, such as input and output.

    def process(self, ir, **keywords):

      self.set_parameters(keywords)
      self.ir = self.merge_input(ir)

      # do the work here...

      return self.output_and_return_ir()

Depending on the nature of the processor, it may parse the input file as source code, or simply read it in from a persistent state. In any case, the result of the input reading is merged in with the existing asg.

    def process(self, ir, **keywords):

      self.set_parameters(keywords)

      for file in self.input:
        self.ir = parse(ir, file))

      return self.output_and_return_ir()

Similarly with the output: if an output parameter is defined, the ir may be stored in that file before it is returned. Or, if the processor is a formatter, the output parameter may indicate the file / directory name to store the formatted output in.

    def process(self, ir, **keywords):

      self.set_parameters(keywords)
      self.ir = self.merge_input(ir)

      self.format(self.output)

      return self.ir

Prev | Up | Next
The ASG | Home | Composing A Pipeline