Function const_decl

Source
pub fn const_decl(input: &str) -> IResult<&str, Vec<Const>>
Expand description

Parse a const declaration, inside a struct. (doesn’t handle the semicolon or preceding whitespace)

use rust_lcm_codegen::parser::{const_decl, Const, ConstValue, PrimitiveType};

assert_eq!(
    const_decl("const int32_t YELLOW=1, GOLDENROD=2, CANARY=3"),
    Ok((
        "",
        vec![
          Const {
            name: "YELLOW".to_owned(),
            ty: PrimitiveType::Int32,
            value: ConstValue::Int32(1)
          },
          Const {
            name: "GOLDENROD".to_owned(),
            ty: PrimitiveType::Int32,
            value: ConstValue::Int32(2)
          },
          Const {
            name: "CANARY".to_owned(),
            ty: PrimitiveType::Int32,
            value: ConstValue::Int32(3)
          },
        ]
    ))
);

assert_eq!(
    const_decl("const double PI=3.14159"),
    Ok((
        "",
        vec![Const {
            name: "PI".to_owned(),
            ty: PrimitiveType::Double,
            value: ConstValue::Double("3.14159".to_owned())
        }]
    ))
);