idl 0.1.1

Library used for the idl language.
Documentation
mod idl_analyzer {
    static IDL_FIRST: &str = r#"
library IdlTest;

enum Enumeration {
    First,
    Second,
    Third,
}

enum TypeEnumeration {
    First: string,
    Second: int[],
    Third: RecordType,
}

record RecordType {
    name: string,
    fields: StructType[],
    data: byte[],
}

struct StructType {
    x: float,
    y: float,
}

const Base10Constant: int = 0x4042;
const IntegerConstant: int = 1123581321345589144233377610987159725844181;
const FloatingPointConstant: float = 3.141592653589793238462643383279;
const StringConstant: string = "Frohe und dankbare Gefühle nach dem Sturm.";

interface InterfaceService {
    hello: (name: string) -> string,
    sum: (first: int, second: int) -> int,
    sendMessage: (message: string) -> stream string,
}
"#;

    use idl::{idl::analyzer, idl::nodes, idl::parser};

    fn to_hex_string(bytes: &[u8]) -> String {
        let strs: Vec<String> = bytes.iter().map(|b| format!("{:02x}", b)).collect();
        strs.join("")
    }

    #[test]
    fn try_this() {
        match parser::Parser::parse(IDL_FIRST) {
            Ok(parser) => match analyzer::Analyzer::resolve(&parser) {
                Ok(analyzer) => {
                    let hex_value = analyzer.library_hash();
                    println!(
                        "library `{}` disgest: {}",
                        analyzer.library_name(),
                        to_hex_string(&hex_value)
                    );

                    assert_eq!(
                        "19bd6b08b8592cf3e6fdf269a4763592",
                        to_hex_string(&hex_value),
                        "Invalid hash for library."
                    );

                    for node in &analyzer.nodes {
                        match node {
                            nodes::IdlNode::TypeStruct(value) => {
                                println!(
                                    "`{}` disgest: {}",
                                    value.ident,
                                    to_hex_string(&value.hash)
                                );

                                for field_node in &value.fields {
                                    if let nodes::StructNode::StructField(field) = field_node {
                                        println!(
                                            "   `{}` disgest: {}",
                                            field.ident,
                                            to_hex_string(&field.hash)
                                        );
                                    }
                                }
                            }
                            nodes::IdlNode::TypeEnum(value) => {
                                println!(
                                    "`{}` disgest: {}",
                                    value.ident,
                                    to_hex_string(&value.hash)
                                );

                                for field_node in &value.fields {
                                    if let nodes::EnumNode::EnumField(field) = field_node {
                                        println!(
                                            "   `{}` disgest: {}",
                                            field.ident,
                                            to_hex_string(&field.hash)
                                        );
                                    }
                                }
                            }
                            nodes::IdlNode::TypeList(value) => {
                                println!(
                                    "`{}` disgest: {}",
                                    value.ident,
                                    to_hex_string(&value.hash)
                                );

                                for field_node in &value.fields {
                                    if let nodes::TypeListNode::TypeListField(field) = field_node {
                                        println!(
                                            "   `{}` disgest: {}",
                                            field.ident,
                                            to_hex_string(&field.hash)
                                        );
                                    }
                                }
                            }
                            nodes::IdlNode::TypeConst(value) => {
                                println!(
                                    "`{}` disgest: {}",
                                    value.ident,
                                    to_hex_string(&value.hash)
                                );
                            }
                            nodes::IdlNode::TypeInterface(value) => {
                                println!(
                                    "`{}` disgest: {}",
                                    value.ident,
                                    to_hex_string(&value.hash)
                                );

                                for field_node in &value.fields {
                                    if let nodes::InterfaceNode::InterfaceField(field) = field_node
                                    {
                                        println!(
                                            "   `{}` disgest: {}",
                                            field.ident,
                                            to_hex_string(&field.hash)
                                        );
                                    }
                                }
                            }
                            _ => {}
                        }
                    }
                }
                Err(err) => panic!("Error: {}", err),
            },
            Err(err) => {
                panic!("{:?} at {:?}", err.1, err.1.get_range());
            }
        }
    }
}