Skip to content

Instantly share code, notes, and snippets.

@kondrak
Last active June 28, 2016 07:02
Show Gist options
  • Save kondrak/96aee631a7a24f75da02e53ec2f34acb to your computer and use it in GitHub Desktop.
Save kondrak/96aee631a7a24f75da02e53ec2f34acb to your computer and use it in GitHub Desktop.
<!-- generic xml format for Rust,C,C++,Lua code generation
Tags:
struct - a structure
enum - enumeration
namespace - namespace!
var - variable (standalone, member if enclosed with struct/enum/namespace, parameter if enclosed by func).
Can be used for typedefs, too.
func - function (standalone, member if enclosed with struct/namespace)
content - contents for overlying element, planned for functions. If tag not present, will make it a function declaration
if supported by language
Tag properties:
name - self explanatory
type - variable type or return type in case of functions
value - self explanatory
scope - private, public, protected equivalents in various languages
No constraints on tag and tag property combinations to accomodate for differences in various languages. Tag properties
will be applied in a given language only if it's applicable, otherwise it will be ignored.
-->
<!-- ////////////////////////////////////////////////////////////////////////////////////////////////// -->
<!-- Define type mappings for Rust generated code. These mappings can be defined for any supported language.
If undefined for a particular language, default values from "type" property in each var/func/etc. tags
will be used. To be moved to a separate file and be included something like:
<config file="types.xml" />
-->
<rust type="int" value="c_int"/> <!-- type="int" will become "c_int" in generated Rust code -->
<rust type="void" value="c_void"/>
<rust type="uint32_t" value="c_uint"/>
<rust type="const char*" value="*const c_char"/>
<rust name="foo" value="Cfoo" /> <!-- in Rust the struct will be named Cfoo instead of foo
<!-- optional mappings for C/C++ -->
<cpp type="..." value="..." />
<!-- optional mappings for Lua -->
<lua type="..." value="..." />
<!-- generate a structure -->
<struct name="foo">
<var type="int" name="bar" /> <!-- member variable, type will be c_int in Rust -->
<var type="uint32_t" name="beep" value="21" /> <!-- default value, C++11 style -->
<func type="void" name="boop" scope="public"> <!-- member function, returns void/c_void, named boop, public -->
<var type="int" name="x" /> <!-- function parameter -->
<var type="int" name="y" />
</func>
<func type="void (*text)"> <!-- function pointer void (*text)(const char* fmt, ...) -->
<var type="const char*" name="fmt" />
<var type="..." />
</func>
</struct>
<!-- enum declaration -->
<enum name="someEnum">
<var name="EnumField1" value="1" /> <!-- enum field with value of 1 -->
...
</enum>
<namespace name="MyNameSpace"> <!-- namespace declaration -->
<func type="void" name="leet"> <!-- function taking no parameters, returns void -->
<content>
...
</content>
</func>
...
</namespace>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment