Crates.io | cyagen |
lib.rs | cyagen |
version | 0.1.10 |
source | src |
created_at | 2022-02-04 22:29:46.983118 |
updated_at | 2023-07-05 15:04:36.041808 |
description | Text file generator based on C file and templates |
homepage | |
repository | https://github.com/robinbreast/cyagen |
max_upload_size | |
id | 527138 |
size | 105,333 |
File generator to reduce the manual effort to prepare another scripting files which contain C code information derived by a C source file.
$ cyagen --source ./example/source/sample.c --temp-dir ./example/template --output-dir ./.output
$ cd .output
$ cmake -S . -B build
$ cmake --build build
$ cd build && ctest
All the available identifiers can be found on docs.rs
Notice: all the new identifiers are not supported on the old style of template (not jinja2 format).
let sourcename = "source";
let code = "\
#include <stdio.h>
static int var = 1;
static int func1(void)
{
return 0;
}
int func2(char c)
{
return func1();
}
";
let temp = "\
// include
{%- for inc in incs %}
{{ inc.captured | safe }}
{%- endfor %}
// local variables
{%- for var in static_vars %}
{{ var.dtype }} {{ var.name }};
{%- endfor %}
// functions
{%- for fnc in fncs %}
{{ fnc.rtype }} {{ fnc.name }}({{ fnc.args }});
{%- endfor %}
";
let parser = cyagen::Parser::parse(code);
let gen = cyagen::generate_using_tera(&parser, temp, sourcename);
println!("{}", gen);
// include
#include <stdio.h>
// local variables
int var;
// functions
int func1();
int func2(char c);
$ cyagen --help
cyagen 0.1.10
Text file generator based on C file and templates
USAGE:
cyagen [OPTIONS] --source <SOURCE>
OPTIONS:
-s, --source <SOURCE> source file path
-t, --temp-dir <TEMP_DIR> template directory
-o, --output-dir <OUTPUT_DIR> output directory
-j, --json-filepath <JSON_FILEPATH> output json file path
-h, --help Print help
-V, --version Print version
$