We have a custom C template engine for web template processing. Let us say that we have a file "index.html" with the following content:
{% #include <stdio.h> %}
<!doctype html>
<html>
<head><title>{{ title }}</title></head>
<body>
{{ body }}
{% printf("test"); %}
{% printf("test2") %}
{% printf("test3"); %}
{%
printf("test4");
printf("test5");
%}
{%
printf("test6");
printf("test7")
%}
{% printf("%d", isalpha('a')); %}
</body>
</html>
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.
When a request is made, the template engine's operation function is called. The function takes the cached code and an array of variables with their types and values as parameters and returns a constant char buffer with the updated variables and logical operations. For the sake of simplicity, let us say that logical operations have the {% ... %} and variables the {{ ... }} syntax respectively.
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 void. 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:
<!doctype html>
<html>
<head><title>title</title></head>
<body>
bodytesttest3test4test5
</body>
</html>
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?