1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>The Processor class</title><link rel="stylesheet" href="synopsis.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="Synopsis Tutorial"><link rel="up" href="scripting.html" title="Chapter3.Scripting and extending synopsis"><link rel="previous" href="ast.html" title="The AST"><link rel="next" href="pipeline.html" title="Composing a pipeline"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><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="ast.html">Prev</a></td><th width="60%" align="center">Chapter3.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"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="processor"></a>The Processor class</h2></div></div><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"></div><p>The requirement that processors can be composed into a pipeline
has some important consequences for its design. The process method takes
an ast argument, which it will operate on, and then return. It is this
ast 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, ast, **keywords):
self.set_parameters(keywords)
self.ast = self.merge_input(ast)
# do the work here...
return self.output_and_return_ast()</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
ast.</p><pre class="programlisting">def process(self, ast, **keywords):
self.set_parameters(keywords)
for file in self.input:
self.ast.merge(self.parse(file))
return self.output_and_return_ast()</pre><p>Similarly with the output: if an output parameter is defined, the
ast 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, ast, **keywords):
self.set_parameters(keywords)
self.ast = self.merge_input(ast)
self.format(self.output)
return set.ast</pre></div><div class="navfooter"><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ast.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 AST</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>
|