4 releases (breaking)
Uses new Rust 2024
| new 0.4.0 | Feb 23, 2026 |
|---|---|
| 0.3.0 | Feb 13, 2026 |
| 0.2.0 | Feb 10, 2026 |
| 0.1.0 | Feb 8, 2026 |
#20 in #py
23KB
595 lines
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()