codeasm 0.4.0

Generate code form ASTs.
Documentation
  • Coverage
  • 1.53%
    2 out of 131 items documented0 out of 33 items with examples
  • Size
  • Source code size: 23.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 10.54 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ZJZCORE/codeasm
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ZJZCORE

codeasm

This library can translate AST into source code for multiple programming languages.

Currently, we support the following programming languages:

  • Go
  • Python

Examples

Go Example

use codeasm::go_asm::*;

let pkg = Pkg(vec![
    "package main".into(),
    "import \"fmt\"".into(),
    FuncDecl {
        name: "main".into(),
        body: vec![
            Call { f: "fmt.Println".into(), args: vec!["\"Hello World\"".into()] }.into(),
        ],
        ..Default::default()
    }.into(),
]);
print!("{pkg}")

Generated code:

package main
import "fmt"
func main(){
fmt.Println("Hello World")
}

Python Example

use codeasm::py_asm::*;

let file = File(vec![
    FuncDef {
        name: "main".into(),
        body: vec![
            Call {
                f: "print".into(),
                args: vec!["\"Hello World\"".into()],
                kwargs: vec![],
            }.into(),
        ],
        ..Default::default()
    }.into(),
    If {
        main: (
            "__name__==\"__main__\"".into(),
            vec![Call { f: "main".into(), ..Default::default() }.into()],
        ),
        ..Default::default()
    }.into(),
]);
print!("{file}")

Generated code:

def main():
    print("Hello World")

if __name__=="__main__":
    main()