11# Simple Perl (Python/C/C++) preprocessor
22
3- This simple preprocessor handles in-comments include directive . Such include
4- statements that are contained inside comments provide additional level of code
5- organization, above the Perl's ` require ` and ` use ` , or Python's ` import ` , or
6- C/C++ ` #include ` native mechanisms. However, these both mechanisms (native and
3+ This simple preprocessor handles in-comments include directives . Such include
4+ statements that are contained inside comments provide an additional level of
5+ code organization, above Perl's ` require ` and ` use ` , Python's ` import ` , or
6+ C/C++ ` #include ` native mechanisms. However, both these mechanisms (native and
77pcpp) can coexist together. Or, the pcpp can be used instead of the native
88mechanism.
99
10- In following Perl and C examples the "abc" code will be copy-pasted into source
11- code by the pcpp, while the "xyz" code will be handled be native include
12- mechanisms:
10+ In the following Perl and C examples the "abc" code will be copy-pasted into
11+ the source code by the pcpp, while the "xyz" code will be handled by native
12+ include mechanisms:
1313
1414``` perl
1515# Perl usage
@@ -47,26 +47,26 @@ perl abc.pl
4747```
4848
4949This looks as if we first "compile" the bunch of Perl source files into the
50- "executable" Perl file and only then run it. Similarly to a c code, which has
51- to be compiled before it can be executed. It is a disadvantage as it requires
52- the extra step ` pcpp abc.in.pl ` . But the following step ` perl abc.pl ` becomes
53- actually simpler:
50+ "executable" Perl file and only then run it. Similarly, a C code has to be
51+ compiled before it can be executed. It is a disadvantage as it requires the
52+ extra step ` pcpp abc.in.pl ` . But the following step ` perl abc.pl ` becomes
53+ simpler:
5454
5555 * now the abc\. pl doesn't require the dependent .pl files to be installed,
56- * the abc\. pl stays a interpreted language code which can be fixed if needed
56+ * the abc\. pl stays an interpreted language code that can be fixed if needed
5757 (comments stay in as well).
5858
59- The same holds for Python. Pcpp-ing is some kind of simple code amalgamation,
59+ The same holds for Python. Pcpp-ing is some kind of simple code amalgamation
6060or a "static linker" for Perl/Python. In C/C++ the pcpp is useful if you want
6161to hide something from the cpp preprocessor.
6262
63- Other reason to use pcpp instead of native require/use/import is that the pcpp
64- processing logic is simpler. And one more reason is that such include process
65- cannot be skewed at the use-time, run-time.
63+ Another reason to use pcpp instead of native require/use/import is that the
64+ pcpp processing logic is simpler. One more reason is that such include process
65+ cannot be skewed at the use-time and run-time.
6666
6767### In-comment directives
6868
69- Hidding the pcpp directives in comments allows to avoid conflicts with the main
69+ Hiding the pcpp directives in comments allows to avoid conflicts with the main
7070language interpreter/compiler/preprocessor, with IDEs or editing modes.
7171Further, this increases the number of comments ;-)
7272
@@ -79,15 +79,15 @@ optional, whitespace between the hash and the "include" word is optional:
7979
8080The additional text after the filename(s) is a comment and is ignored,
8181filenames have to be identified by the .pl (or .py/.h) suffix or have to be
82- quoted for the parser to find the begin of comment:
82+ quoted for the parser to find the beginning of the comment:
8383
8484```
8585# include abc.pl xyz.pl comment text which is ignored
8686# include abc.py xyz.py # visualy more noticeable comment
8787// include abc.h comment in C/C++
8888```
8989
90- Multiple hashes (slashes) are not accepted, thus following code are just
90+ Multiple hashes (slashes) are not accepted, the following code are just
9191comments without any effect:
9292
9393```
@@ -107,15 +107,16 @@ Included content in the pcpp output is "watermarked" by the `# included` and
107107# end "abc.pl"
108108```
109109
110- Indentation of the include statement is propagated into output. For instance
111- a two-spaces indentation of the hash of include statement in perl code:
110+ Indentation of the include statement is propagated into output. For instance a
111+ two-space indentation of the hash of the include statement in perl code:
112112
113113``` perl
114114some(code);
115115 # include abc.pl
116116```
117117
118- will lead to added two spaces to the original indentation in included file:
118+ will lead to adding two spaces to the original indentation in the included
119+ file:
119120
120121``` perl
121122some(code);
@@ -126,26 +127,26 @@ some(code);
126127```
127128
128129The language is autodetected according to the suffix of the input file: ` .pl ` ,
129- ` .py ` , ` .c ` or ` .c++ ` .
130+ ` .py ` , ` .c ` , or ` .c++ ` .
130131
131132### Paths resolving
132133
133- Include paths can be spcified as a filename only ` # include abc.pl ` or
134+ Include paths can be specified as a filename only ` # include abc.pl ` or
134135specifying also a part of the path ` # include xy/abc.pl ` or `# include
135136yz/abc.pl` to distinguish between equal filenames in different directories.
136137The resolving algorithm is:
137138
138- 1 . trying direct path from current working directory,
139- 2 . trying path from directory of file from which the include is called,
140- 3 . try to find file recursively in any subdirectory of current working directory (in the depth order),
141- 4 . strip the directory part from include file name, and try to find it just by the filename.
139+ 1 . trying direct path from the current working directory,
140+ 2 . trying the path from the directory of the file from which the include is called,
141+ 3 . try to find files recursively in any subdirectory of the current working directory (in the depth order),
142+ 4 . strip the directory part from the included file name, and try to find it just by the filename.
142143
143144In the case of conflict, i.e. ` # include "abc.pl" ` where two ` abc.pl ` are
144- available, the first one is chosen: ` ./abc.pl ` is direct path so has higher
145- priority than the ` xy/abc.pl ` .
145+ available, the first one is chosen: ` ./abc.pl ` is the direct path so it has a
146+ higher priority than the ` xy/abc.pl ` .
146147
147- Double includes are avoided, so the file from given path is copy-pasted to the
148- output only once, on the place of the firste appearance of the include
148+ Double includes are avoided, so the file from the given path is copy-pasted to
149+ the output only once, on the place of the first appearance of the include
149150statement.
150151
151152Missing include files are by default silently ignored, or reported in the
@@ -154,9 +155,9 @@ verbose mode (-v switch).
154155### Triple comments
155156
156157Pcpp preserves comments to allow the Perl or Python output code to be readable
157- as best as possible in order to allow the output to be hacked/fixed.
158+ as best as possible to allow the output to be hacked/fixed.
158159
159- However, to allow programmer to request the removal of comments from the
160+ However, to allow the programmer to request the removal of comments from the
160161output, we introduce the "triple comments":
161162
162163```
@@ -176,7 +177,7 @@ the pcpp processed code, not the code you wrote.
176177
177178### Uninclude
178179
179- Watermarked pcpp output allows to remove included parts and return to the
180+ Watermarked pcpp output allows the removal of included parts and return to the
180181original source code using the ` uninclude ` tool. This can be useful when
181182building "libraries" which can recursively pack all dependencies, which can be
182183stripped off when not needed (when already provided by another "library").
@@ -194,7 +195,7 @@ instance the following included content:
194195# end abc.pl
195196```
196197
197- will be flattend by uninclude to:
198+ will be flattened by uninclude to:
198199
199200```
200201# include abc.pl
@@ -215,20 +216,20 @@ which when included back will become:
215216
216217### Pcpp in Makefile
217218
218- Example to make ` xyz ` from from its source ` xyz.pl ` and two included files:
219+ Example to make ` xyz ` from its source ` xyz.pl ` and two included files:
219220
220221``` makefile
221222xyz : xyz.pl inc1.pl inc2.pl
222223 echo ' #!/usr/bin/perl' > $@
223224 pcpp $< >> $@
224225 @chmod 755 $@
225- @sync # to ensure the result is saved before used in the next rule
226+ @sync # to ensure the result is saved before being used in the next rule
226227```
227228
228229 1. generate # ! interpreter identifier
229230 2. build `xyz` from `xyz.pl`
230231 3. make it executable
231- 4. sync the result before it is used by other makefile rule (otherwise it can be incomplete)
232+ 4. sync the result before it is used by another makefile rule (otherwise it can be incomplete)
232233
233234More complex example :
234235
@@ -248,13 +249,16 @@ $(OUTPUT): %: %.pl $(DEPENDENCIES) Makefile
248249```
249250
250251 * `DEPENDENCIES` are a list of files to be included obtained by `pcpp -lp`
251- * `SIGN` is a variable made available from Makefile into script
252+ * `SIGN` is a variable made available from Makefile into the script
252253
253254# ## Dependency files
254255
255256The `pcpp -d target_name` can be used to generate a dependency file for
256257Makefile. Compared to the `-lp` option, the `-d` and `-dd` options also add
257- the input file into the list. Example Makefile :
258+ the input file into the list and nonexistent files too. Nonexistent include
259+ files are files that will be generated by the Makefile. A full path is
260+ required for them to work properly (relative path is ok if it is complete).
261+ Example Makefile :
258262
259263``` makefile
260264# require rebuild of the dependencies file .abc.d when processing abc.pl
@@ -282,7 +286,7 @@ to any `/bin` directory for a system-wide installation.
282286
283287# ## Under the hood
284288
285- The pcpp itself is processed by the pcpp, so its source code is example how to
286- use the pcpp.
289+ The pcpp itself is processed by the pcpp, so its source code is an example of
290+ how to use the pcpp.
287291
288292<br><div align=right><i>R.Jaksa 2008,2024</i></div>
0 commit comments