#idl #parser #text #definition #language #interface #omg

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

#2833 in Parser implementations

Download history 70/week @ 2024-07-24 51/week @ 2024-07-31 74/week @ 2024-08-07 122/week @ 2024-08-14 25/week @ 2024-08-21 30/week @ 2024-08-28 21/week @ 2024-09-04 25/week @ 2024-09-11 21/week @ 2024-09-18 44/week @ 2024-09-25 31/week @ 2024-10-02 38/week @ 2024-10-09 29/week @ 2024-10-16 12/week @ 2024-10-23 27/week @ 2024-10-30 38/week @ 2024-11-06

112 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
~31K SLoC