fluidattacks-blends-domain 0.36.0

Blends functional core: pure AST graph to syntax graph (no_std)
Documentation
use crate::syntax::readers::rust;
use crate::syntax::SyntaxReader;

pub fn dispatcher(node_type: &str) -> Option<SyntaxReader> {
    match node_type {
        "source_file" => Some(rust::source_file::reader),
        "boolean_literal" => Some(rust::boolean_literal::reader),
        "integer_literal" | "float_literal" => Some(rust::integer_literal::reader),
        "string_literal" | "char_literal" | "raw_string_literal" => {
            Some(rust::string_literal::reader)
        }
        "identifier" | "self" | "shorthand_field_identifier" | "type_identifier" => {
            Some(rust::identifier::reader)
        }
        "scoped_identifier" | "scoped_type_identifier" => Some(rust::scoped_identifier::reader),
        "line_comment"
        | "block_comment"
        | "doc_comment"
        | "inner_attribute_item"
        | "attribute_item"
        | "extern_crate_declaration"
        | "empty_statement" => Some(rust::comment::reader),
        _ => None,
    }
}

#[cfg(test)]
mod tests {
    use super::dispatcher;

    #[test]
    fn maps_the_implemented_rust_node_types() {
        assert!(dispatcher("source_file").is_some());
        assert!(dispatcher("boolean_literal").is_some());
        assert!(dispatcher("integer_literal").is_some());
        assert!(dispatcher("float_literal").is_some());
        assert!(dispatcher("string_literal").is_some());
        assert!(dispatcher("char_literal").is_some());
        assert!(dispatcher("raw_string_literal").is_some());
        assert!(dispatcher("identifier").is_some());
        assert!(dispatcher("self").is_some());
        assert!(dispatcher("shorthand_field_identifier").is_some());
        assert!(dispatcher("type_identifier").is_some());
        assert!(dispatcher("scoped_identifier").is_some());
        assert!(dispatcher("scoped_type_identifier").is_some());
        assert!(dispatcher("line_comment").is_some());
        assert!(dispatcher("block_comment").is_some());
        assert!(dispatcher("doc_comment").is_some());
        assert!(dispatcher("inner_attribute_item").is_some());
        assert!(dispatcher("attribute_item").is_some());
        assert!(dispatcher("extern_crate_declaration").is_some());
        assert!(dispatcher("empty_statement").is_some());
    }
}