<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Processor class</title><link rel="stylesheet" href="synopsis.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><link rel="start" href="index.html" title="Synopsis Tutorial" /><link rel="up" href="scripting.html" title="Chapter 3. Scripting And Extending Synopsis" /><link rel="prev" href="asg.html" title="The ASG" /><link rel="next" href="pipeline.html" title="Composing A Pipeline" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">The Processor class</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="asg.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Scripting And Extending Synopsis</th><td width="20%" align="right"> <a accesskey="n" href="pipeline.html">Next</a></td></tr></table></div><div class="section" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="processor"></a>The Processor class</h2></div></div></div><p>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.</p><div class="mediaobject"><img src="images/processor.png" width="432" /></div><p>The requirement that processors can be composed into a pipeline has some important consequences for its design. The process method takes an <code class="varname">ir</code> argument, which it will operate on, and then return. It is this <code class="varname">ir</code> 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.</p><pre class="programlisting">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()</pre><p>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.</p><pre class="programlisting">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()</pre><p>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.</p><pre class="programlisting">def process(self, ir, **keywords): self.set_parameters(keywords) self.ir = self.merge_input(ir) self.format(self.output) return self.ir</pre></div><div class="navfooter"><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="asg.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="scripting.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pipeline.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">The ASG </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Composing A Pipeline</td></tr></table></div></body></html>