t4_idl_parser

Crates.iot4_idl_parser
lib.rst4_idl_parser
version0.1.1
sourcesrc
created_at2022-11-07 01:41:18.863184
updated_at2022-11-07 01:43:11.18451
descriptionA parser for the interface definition language (IDL) specified by Object Management Group (OMG) written in Rust. This supports IDL version 4.2.
homepagehttps://github.com/tier4/idl_parser
repositoryhttps://github.com/tier4/idl_parser
max_upload_size
id706886
size148,780
ytakano (ytakano)

documentation

README

T4 IDL Parser

A parser for the interface definition language (IDL) specified by Object Management Group (OMG) written in Rust. This supports IDL version 4.2.

Example

use t4_idl_parser::{parse, Span};
use nom_greedyerror::convert_error;

let input = r#"
// generated from rosidl_adapter/resource/msg.idl.em
// with input from example_msg/bar/Buz.msg
// generated code does not contain a copyright notice

module example_msg {
    module msg {
        struct Buz {
            string c;

            @verbatim (language="comment", text="http://wiki.ros.org/std_msgs")
            sequence<int32> o;
        };
    };
};"#;

match parse(input) {
    Ok(result) => {
        println!("{:#?}", result);
    }
    Err(e) => {
        eprintln!("{e}");
        panic!();
    }
}

This will output a result as follows.

[
    Module(
        Module {
            id: "example_msg",
            definitions: [
                Module(
                    Module {
                        id: "msg",
                        definitions: [
                            Type(
                                ConstrType(
                                    Struct(
                                        Def(
                                            StructDef {
                                                id: "Buz",
                                                members: [
                                                    Member {
                                                        type_spec: Template(
                                                            String(
                                                                UnlimitedSize,
                                                            ),
                                                        ),
                                                        declarators: [
                                                            Simple(
                                                                "c",
                                                            ),
                                                        ],
                                                    },
                                                    Member {
                                                        type_spec: Template(
                                                            Sequence(
                                                                Unlimited(
                                                                    PrimitiveType(
                                                                        Int32,
                                                                    ),
                                                                ),
                                                            ),
                                                        ),
                                                        declarators: [
                                                            Simple(
                                                                "o",
                                                            ),
                                                        ],
                                                    },
                                                ],
                                                inheritance: None,
                                            },
                                        ),
                                    ),
                                ),
                            ),
                        ],
                    },
                ),
            ],
        },
    ),
]

Limitation

C/C++ like preprocessor is not supported.

Commit count: 40

cargo fmt