Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
da4ffeec
Commit
da4ffeec
authored
Nov 09, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No need to have documentation for a module which not accepted in the library.
parent
249aaeda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
87 deletions
+0
-87
Doc/lib/libcompilerlike.tex
Doc/lib/libcompilerlike.tex
+0
-87
No files found.
Doc/lib/libcompilerlike.tex
deleted
100644 → 0
View file @
249aaeda
\section
{
\module
{
compilerlike
}
---
framework code for building compiler-like programs.
}
\declaremodule
{
standard
}{
set
}
\modulesynopsis
{
Framework code for building compiler-like programs.
}
\moduleauthor
{
Eric S. Raymond
}{
esr@thyrsus.com
}
\sectionauthor
{
Eric S. Raymond
}{
esr@thyrsus.com
}
There is a common `compiler-like' pattern in Unix scripts which is useful
for translation utilities of all sorts. A program following this pattern
behaves as a filter when no argument files are specified on the command
line, but otherwise transforms each file individually into a corresponding
output file.
The
\function
{
filefilter
}
,
\function
{
linefilter
}
, and
\function
{
sponge
}
functions in this module provide a framework and
glue code to make such programs easy to write. You supply a function
to massage the file data; depending on which entry point you use, it
can take input and output file pointers, or it can take a string
consisting of the entire file's data and return a replacement, or it
can take in succession strings consisting of each of the file's lines
and return a translated line for each.
All three of these entry points take a name, an argument list of files,
a data transformation function, and a name transformation function.
They differ only in the arguments they pass to the transformation
function when it is called.
The name argument is not used by the functions in this module, it is
simply passed as the first argument to the transformation function.
Typically it is a string that names the filter and is used in
generating error messages, but it could be arbitrary data.
The second argument is interpreted as a list of filenames. The files
are transformed in left to right order in the list. A filename
consisting of a dash is interpreted as a directive to read from
standard input (this can be useful in pipelines).
The third argument is the data transformation function.
Interpretation of this argument varies across the three
entry points and is described below.
The fourth, optional argument is a name transformation function or
name suffix string. If it is of string type, the shortest suffix of each
filename beginning with the first character of the argument string
is stripped off. If the first character of the argument does not
occur in the filename, no suffix is removed. Then the name suffix
argument is concatenated to the end of the stripped filename. (Thus,
a name suffix argument of ".x" will cause the filenames foo.c and
bar.d to be transformed to foo.x and bar.x respectively.)
If the fourth argument is specified and is a function, the name of the
input file is passed to it and the return value of the function
becomes the name of the output software. If this argument is not
specified, the imnput file is replaced with the transformed version.
Replacement of each file is atomic and doesn't occur until the
translation of that file has completed. Any tempfiles are removed
automatically on any exception thrown by the translation function,
and the exception is then passed upwards.
\begin{funcdesc}
{
filefilter
}{
name, file, arguments, trans
_
data
\optional
{
,trans
_
file
}}
Filter using a function taking the name, filename, and two file-object
arguments. The function is expected to read data from the input file
object, transform it, and write the data to the output file object.
When the function terminates, the translation is done. The return
value of the transformation function is not used.
\end{funcdesc}
\begin{funcdesc}
{
linefilter
}{
name, file, arguments,trans
_
data
\optional
{
,trans
_
file
}}
Filter using a function taking the name, the filename, and a string
argument. The return value of the function should be a string. This
function is applied to each line in the input file in turn; the return
values become the lines of the transformed file.
\end{funcdesc}
\begin{funcdesc}
{
sponge
}{
name, file, arguments, trans
_
data
\optional
{
, trans
_
file
}}
Filter using a function taking the name, the filename, and a string
argument. The return value of the function should be a string. The
function will be passed the entire contents of the input file as a
string. The string return value of the function will become the
entire contents of the transformed file.
\end{funcdesc}
# End
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment