#idl #parser #text #definition #interface #language #group

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.

2 releases

0.1.1 Nov 7, 2022
0.1.0 Nov 7, 2022

#2171 in Parser implementations

Download history 108/week @ 2024-03-14 109/week @ 2024-03-21 91/week @ 2024-03-28 123/week @ 2024-04-04 275/week @ 2024-04-11 33/week @ 2024-04-18 26/week @ 2024-04-25 33/week @ 2024-05-02 31/week @ 2024-05-09 34/week @ 2024-05-16 100/week @ 2024-05-23 62/week @ 2024-05-30 21/week @ 2024-06-06 34/week @ 2024-06-13 46/week @ 2024-06-20 7/week @ 2024-06-27

116 downloads per month
Used in safe_drive_msg

Custom license

140KB
3K SLoC

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.

Dependencies

~1.5MB
~32K SLoC