{"id":13753685,"url":"https://github.com/linkdd/astmaker","last_synced_at":"2025-04-09T21:19:17.738Z","repository":{"id":166504108,"uuid":"642005714","full_name":"linkdd/astmaker","owner":"linkdd","description":"Build Abstract Syntax Trees and tree-walking models quickly in Rust.","archived":false,"fork":false,"pushed_at":"2024-01-11T19:39:48.000Z","size":11,"stargazers_count":120,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T21:19:12.376Z","etag":null,"topics":["abstract-syntax-tree","ast","macros-rust","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/astmaker/latest/astmaker/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linkdd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["linkdd"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-05-17T16:01:31.000Z","updated_at":"2025-03-19T18:52:19.000Z","dependencies_parsed_at":"2024-01-16T00:22:31.083Z","dependency_job_id":null,"html_url":"https://github.com/linkdd/astmaker","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"0660a89977406b526108590810022e9882e8a596"},"previous_names":["linkdd/astmaker"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Fastmaker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Fastmaker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Fastmaker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Fastmaker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdd","download_url":"https://codeload.github.com/linkdd/astmaker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111973,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abstract-syntax-tree","ast","macros-rust","rust"],"created_at":"2024-08-03T09:01:27.321Z","updated_at":"2025-04-09T21:19:17.715Z","avatar_url":"https://github.com/linkdd.png","language":"Rust","funding_links":["https://github.com/sponsors/linkdd"],"categories":["Rust"],"sub_categories":[],"readme":"# astmaker\n\n[![Crates.io](https://img.shields.io/crates/v/astmaker?style=flat-square)](https://crates.io/crates/astmaker)\n[![Crates.io](https://img.shields.io/crates/l/astmaker?style=flat-square)](https://crates.io/crates/astmaker)\n[![Crates.io](https://img.shields.io/crates/d/astmaker?style=flat-square)](https://crates.io/crates/astmaker)\n[![docs.rs](https://img.shields.io/docsrs/astmaker?style=flat-square)](https://docs.rs/astmaker)\n\nBuild Abstract Syntax Trees and tree-walking models quickly in Rust.\n\n## Example\n\nThis example creates an AST for simple math expressions, and an interpreter to\nevaluate the result:\n\n```rust\nuse astmaker::{ast, model};\n\n#[derive(Debug, Clone, PartialEq)]\npub enum BinOp {\n  Add,\n  Sub,\n  Mul,\n  Div,\n}\n\n#[derive(Debug, Clone, PartialEq)]\npub enum UnOp {\n  Add,\n  Sub,\n}\n\nast!{\n  location = ();\n\n  pub node Expression =\n    | BinOp -\u003e Node\u003cBinaryOperation\u003e\n    | UnOp -\u003e Node\u003cUnaryOperation\u003e\n    | Num -\u003e Node\u003cNumber\u003e\n    ;\n\n  pub node BinaryOperation = {\n    lhs: Node\u003cExpression\u003e,\n    op: BinOp,\n    rhs: Node\u003cExpression\u003e,\n  }\n\n  pub node UnaryOperation = {\n    op: UnOp,\n    expr: Node\u003cExpression\u003e,\n  }\n\n  pub node Number = {\n    value: f64,\n  }\n}\n\npub struct Interpreter;\n\nmodel!{\n  impl Interpreter -\u003e f64 {\n    where Expression =\u003e {\n      match node.data.as_mut() {\n        Expression::BinOp(child_node) =\u003e context.visit(child_node),\n        Expression::UnOp(child_node) =\u003e context.visit(child_node),\n        Expression::Num(child_node) =\u003e context.visit(child_node),\n      }\n    },\n    where BinaryOperation =\u003e {\n      let lhs = context.visit(\u0026mut node.data.lhs);\n      let rhs = context.visit(\u0026mut node.data.rhs);\n\n      match node.data.op {\n        BinOp::Add =\u003e lhs + rhs,\n        BinOp::Sub =\u003e lhs - rhs,\n        BinOp::Mul =\u003e lhs * rhs,\n        BinOp::Div =\u003e lhs / rhs,\n      }\n    },\n    where UnaryOperation =\u003e {\n      let val = context.visit(\u0026mut node.data.expr);\n\n      match node.data.op {\n        UnOp::Add =\u003e val,\n        UnOp::Sub =\u003e -val,\n      }\n    },\n    where Number =\u003e node.data.value,\n  }\n}\n\n#[test]\nfn eval() {\n  let mut tree = Node::new((), Expression::BinOp(\n    Node::new((), BinaryOperation {\n      lhs: Node::new((), Expression::Num(\n        Node::new((), Number { value: 1.0 })\n      )),\n      op: BinOp::Add,\n      rhs: Node::new((), Expression::Num(\n        Node::new((), Number { value: 2.0 })\n      ))\n    })\n  ));\n\n  let mut interpreter = Interpreter;\n\n  assert_eq!(interpreter.visit(\u0026mut tree), 3.0);\n}\n```\n\n## Roadmap\n\n - [x] :memo: Documentation\n - [x] :sparkles: Generics support\n - [x] :sparkles: Lifetimes support\n - [ ] :construction_worker: Github workflows to build, test \u0026 publish crate\n\n## License\n\nThis project is released under the terms of the [MIT License](./LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Fastmaker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdd%2Fastmaker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Fastmaker/lists"}