Function struct_decl

Source
pub fn struct_decl(input: &str) -> IResult<&str, Struct>
Expand description

Parse a whole struct declaration.

use rust_lcm_codegen::parser::{struct_decl, Struct, Const, ConstValue, PrimitiveType, StructMember, Field, Type};

assert_eq!(
    struct_decl("struct empty_struct { }"),
    Ok((
        "",
        Struct {
          name: "empty_struct".to_string(),
          members: vec![],
        }
    ))
);

assert_eq!(
    struct_decl("struct my_struct {\n  const int32_t YELLOW=1;\n  int32_t color;\n}"),
    Ok((
        "",
        Struct {
          name: "my_struct".to_string(),
          members: vec![
            StructMember::Const(
              Const {
                name: "YELLOW".to_owned(),
                ty: PrimitiveType::Int32,
                value: ConstValue::Int32(1)
              }
            ),
            StructMember::Field(
              Field {
                name: "color".to_owned(),
                ty: Type::Primitive(PrimitiveType::Int32),
              }
            ),
          ]
        }
    ))
);