|
2 ay önce | |
---|---|---|
src | 2 ay önce | |
.gitignore | 2 ay önce | |
Cargo.toml | 2 ay önce | |
README.md | 2 ay önce | |
test.idl | 2 ay önce |
RustDDS-Gen 是一个用于将 IDL(接口定义语言)文件转换为 Rust 代码的工具。该工具专为 RustDDS 项目设计,支持解析 IDL 文件并生成相应的 Rust 结构体、枚举、常量等。
RustDDS-Gen 提供了一个完整的 IDL 到 Rust 代码的转换流程,主要包括:
RustDDS-Gen/
├── Cargo.toml # 项目配置和依赖
├── src/ # 源代码目录
│ ├── main.rs # 主程序入口
│ ├── parser/ # IDL 解析器
│ │ ├── mod.rs # 解析器主模块
│ │ ├── idl.pest # Pest 语法规则
│ │ ├── interface.rs # 接口解析
│ │ └── union.rs # 联合类型解析
│ └── codegen/ # 代码生成器
│ ├── mod.rs # 代码生成主模块
│ ├── interface.rs # 接口代码生成
│ ├── typedef.rs # 类型定义代码生成
│ └── union.rs # 联合类型代码生成
├── test.idl # 测试用 IDL 文件
└── test_output.rs # 测试生成的 Rust 代码
rustdds-gen --input <IDL文件路径> --output <Rust文件输出路径>
-i, --input <文件路径>
: 指定输入的 IDL 文件-o, --output <文件路径>
: 指定输出的 Rust 文件-d, --debug
: 启用调试输出--parse-only
: 只解析语法,不生成代码--verbose
: 打印详细的解析过程--print-ast
: 打印语法树--dump-ast <文件路径>
: 将解析结果保存到文件# 基本用法
rustdds-gen --input test.idl --output test_output.rs
# 调试模式
rustdds-gen --input test.idl --output test_output.rs --debug
# 只解析不生成代码
rustdds-gen --input test.idl --output test_output.rs --parse-only
# 保存语法树到文件
rustdds-gen --input test.idl --output test_output.rs --dump-ast ast.json
RustDDS-Gen 支持以下 IDL 特性:
cargo build
cargo test
src/parser/idl.pest
中添加新的语法规则src/parser/mod.rs
中添加相应的解析函数src/codegen/mod.rs
中添加相应的代码生成函数[待定]
欢迎提交问题报告和拉取请求。对于重大更改,请先开启一个问题进行讨论。