use crate::{
query::{adj_ast, match_ast_d},
syntax::{
builders::method_invocation::{build_method_invocation_node, DirectChildren},
SyntaxGraphArgs, SyntaxGraphError,
},
CodeGraph, NodeId,
};
use alloc::borrow::ToOwned;
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
if graph.label_type(n_id) == Some("print_intrinsic") {
let mut expr_id = None;
if let Some(&child_id) = adj_ast(graph, n_id, Some(1), &[]).get(1) {
if graph.label_type(child_id) == Some("parenthesized_expression") {
expr_id = adj_ast(graph, child_id, Some(1), &[]).get(1).copied();
}
}
let children = DirectChildren {
expression_id: expr_id,
..Default::default()
};
return build_method_invocation_node(args, n_id, "print".to_owned(), children, None)
.map(Some);
}
if graph.label_type(n_id) == Some("exit_statement") {
let args_id = adj_ast(graph, n_id, Some(1), &[]).get(2).copied();
let children = DirectChildren {
arguments_id: args_id,
..Default::default()
};
return build_method_invocation_node(args, n_id, "exit".to_owned(), children, None)
.map(Some);
}
let args_id = match_ast_d(graph, n_id, "echo", Some(1));
let children = DirectChildren {
arguments_id: args_id,
..Default::default()
};
build_method_invocation_node(args, n_id, "echo".to_owned(), children, None).map(Some)
}