Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to emulate C logic and syntax in a template engine (preprocessor)?
    primarykey
    data
    text
    <p>We have a custom <strong>C template engine</strong> for web template processing. Let us say that we have a file "index.html" with the following content:</p> <pre><code>{% #include &lt;stdio.h&gt; %} &lt;!doctype html&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;{{ title }}&lt;/title&gt;&lt;/head&gt; &lt;body&gt; {{ body }} {% printf("test"); %} {% printf("test2") %} {% printf("test3"); %} {% printf("test4"); printf("test5"); %} {% printf("test6"); printf("test7") %} {% printf("%d", isalpha('a')); %} &lt;/body&gt; &lt;/html&gt; </code></pre> <p>When the template engine is called (initialized), it scans all the files in a particular "views" folder. The "index.html" file happens to be in this folder. It is scanned and cached in memory of the main program which has called the template engine.</p> <p>When a <strong>request</strong> is made, the template engine's operation function is called. The function takes the <strong>cached code</strong> and an <strong>array</strong> of <strong>variables</strong> with their types and values as parameters and <strong>returns</strong> a constant char <strong>buffer</strong> with the updated variables and logical operations. For the sake of simplicity, let us say that logical operations have the <strong>{% ... %}</strong> and variables the <strong>{{ ... }}</strong> syntax respectively.</p> <p>One should be able to use C functions and general logic in the markup language. You should even be able to define functions in templates. If something goes wrong, the variable or logical operation should return <strong>void</strong>. The end result of our called "index.html" page with "body" and "title" as the variables of {{ body }} and {{ title }} respectively should look like this:</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt;&lt;title&gt;title&lt;/title&gt;&lt;/head&gt; &lt;body&gt; bodytesttest3test4test5 &lt;/body&gt; &lt;/html&gt; </code></pre> <p>How does one emulate the logic and syntax of the C language? Is this possible? Do you need to go as far as to develop a custom library of the language's operations and function calls or is there a simpler solution? What is the best way of implementing such a solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload