# libparcival Parcival is a templating engine for C. The template files are compiled into C files that can then be compiled with the rest of the application. To access the template code the `template.h` file is used (see "Using Templates"). ## Building `make all` will build the executeable for translating the templates and the static library that includes the template registry. ## Dependencies & Compatibility Besides a C compiler `lex` and `yacc` are also required. The `Makefile` uses `flex` and `bison` respecively but I think I only used non-specific features. As for the C compiler support for GNU function attributes is needed. So `gcc` or `clang` should work, maybe others as well. # Usage ## Template Format Template files have the following syntax: ``` [meta section] %% [main section] ``` The meta section can contain the parameter list for the template as well as static statement blocks for optional includes, definitions, ... The main section contains the content of the template. Here statement blocks and output blocks are allowed. ### Parameter Block The parameter block has the following syntax: ``` {$ [parameter list ] $} ``` The parameter list is comma-seperated list of the parameters of the template including their type. Example: ``` {$ char* title, user_t* users, size_t numberOfUsers $} ``` Note: All types that C does not provide by default have to be declared in a statement block in the meta section or in a header file included by a statement block in the meta section. In the example above this would apply to the type `user_t`. ### Statement Block Statement blocks have the following syntax: ``` {% [C statements] %} ``` In the meta section these blocks can be used to define datatypes - even functions - and include any needed header files. Anything that got declared this way can be used as a parameter type in a parameter block. Examples: ``` {% #include "someheader.h" %} {% struct s { int i; }; %} ``` In the main section these blocks will open a template block. This template blocks has to be closed with `{% end %}`. Statement blocks in the main section are meant to be used for loops and conditions. Example: ``` {% for(int i = 0; i < 10; i++) %} This string will be printed 10 times. {% end %} ``` Inside statement blocks in the main section the parameters as well as all local variables of parent statement blocks can be accessed. ### Output Block Output blocks have the following syntax: ``` {{ [format string] {, format parameters} }} ``` These blocks are effectively `printf()`-calls. In the rendered templated they will be replaced by the corresponding output. Example: ``` {{ "foo: %s - %d", "bar", 69 }} ``` ### Complete Example ``` {% #include "entities.h" %} {$ char* title, struct user* users, size_t userno $} %%