From aac04585ea5c077f3ea0bddd66a11c2aff390e50 Mon Sep 17 00:00:00 2001 From: technicallyagd <43739261+technicallyagd@users.noreply.github.com> Date: Wed, 17 Oct 2018 18:51:51 +0800 Subject: [PATCH] Elaborate on source code filter usage in the documentation. (#9407) * Elaborate on source code filter usage. Also gives it an abbreviation, SCF. * Fix the code block formatting * Trim off the unintended usage with import. (cherry picked from commit 88adf775691411a526c18d82b1e6bd83b653f343) --- doc/filters.rst | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/filters.rst b/doc/filters.rst index 1937b187c7..e8106749e2 100644 --- a/doc/filters.rst +++ b/doc/filters.rst @@ -4,7 +4,7 @@ Source Code Filters .. contents:: -A `Source Code Filter` transforms the input character stream to an in-memory +A `Source Code Filter (SCF)` transforms the input character stream to an in-memory output stream before parsing. A filter can be used to provide templating systems or preprocessors. @@ -23,10 +23,23 @@ just like an ordinary procedure call with named or positional arguments. The available parameters depend on the invoked filter. Before version 0.12.0 of the language ``#!`` was used instead of ``#?``. -**Hint:** With ``--hint[codeBegin]:on```or ``--verbosity:2`` -(or higher) Nim lists the processed code after each filter -application. +**Hint:** With ``--hint[codeBegin]:on`` or ``--verbosity:2`` +(or higher) while compiling or `nim check`, Nim lists the processed code after +each filter application. +Usage +===== + +First, put your SCF code in a separate file with filters specified in the first line. +**Note:** You can name your SCF file with any file extension you want, but the conventional extension is ``.tmpl``. + +If we use `generateXML` code shown above and call the SCF file `xmlGen.tmpl` +In your `main.nim`: + +.. code-block:: nim + include "xmlGen.tmpl" + + echo generateXML("John Smith","42") Pipe operator =============