cyagen
C code based Yet Another GENerator
- Scan C source file using the simple pattern matching to capture the elements in the code
- Generate text based files using template files
- Supported elements are inclusion, local variable, and functions
Available tags in template file
- @sourcename@ : it is given as an argument from command line
- @date@ : generated date
- @incs@ : the list of inclusion statement such as
#include <stdio.h>
- @captured@ : the captured raw string
- @end-incs@ : the end of incs block
- @local-vars@ : the list of static variables
- @captured@ : the captured raw string
- @name@ : variable name
- @dtype@ : variable data type
- @end-local-vars@ : the end of local-var bolck
- @fncs@ or @fncs0@ : the list of all the functions
- @captured@ : the captured raw string
- @name@ : the function name
- @rtype@ : the return data type of the function
- @args@ : the list of arguments with data types
- @atypes@ : the list of only arguments' data types
- @end-fncs@ or @end-fncs0@ : the end of fncs or fncs0 block
- @ncls@ or @ncls-once@ : the list of nested calls, no duplicate callee with ncls-once
- @callee.name@ : the function name of callee
- @callee.rtype@ : the return type of callee
- @callee.rtype.change(\ : to change return data type during generation
- @callee.rtype.variable(\ : \void
- @callee.rtype.value(\ : \void
- @callee.args@ : the argument list string
- @callee.atypes@ : only arguments' data types
- @caller.name@ : the function name of caller
- @caller.rtype@ : the return type of caller
- @caller.args@ : the argument list string
- @caller.atypes@ : only arguments' data types
- @end-ncls@ or @end-ncls-once@ : the end of ncls or ncls-once block
Example
```
let sourcename = "source";
let code = "\
include
static int var = 1;
static int func1(void)
{
return 0;
}
int func2(char c)
{
return func1();
}
";
let temp = "\
// include
@incs@@captured@
@end-incs@
// local variables
@local-vars@@dtype@ @name@;
@end-local-vars@
// functions
@fncs@@rtype@ @name@(@args@);
@end-fncs@
";
let parser = cyagen::Parser::parse(code);
let gen = cyagen::generate(&parser, temp, sourcename);
```
License: MIT