fork of https://github.com/tree-sitter/tree-sitter-graph

Adds match node debug attr

Co-authored-by: Hendrik van Antwerpen <hendrikvanantwerpen@github.com>

Changed files
+57
src
+5
src/execution.rs
··· 256 256 pub(crate) lazy: bool, 257 257 pub(crate) location_attr: Option<Identifier>, 258 258 pub(crate) variable_name_attr: Option<Identifier>, 259 + pub(crate) match_node_attr: Option<Identifier>, 259 260 } 260 261 261 262 impl<'a, 'g> ExecutionConfig<'a, 'g> { ··· 266 267 lazy: false, 267 268 location_attr: None, 268 269 variable_name_attr: None, 270 + match_node_attr: None, 269 271 } 270 272 } 271 273 ··· 273 275 self, 274 276 location_attr: Identifier, 275 277 variable_name_attr: Identifier, 278 + match_node_attr: Identifier, 276 279 ) -> Self { 277 280 Self { 278 281 functions: self.functions, ··· 280 283 lazy: self.lazy, 281 284 location_attr: location_attr.into(), 282 285 variable_name_attr: variable_name_attr.into(), 286 + match_node_attr: match_node_attr.into(), 283 287 } 284 288 } 285 289 ··· 290 294 lazy, 291 295 location_attr: self.location_attr, 292 296 variable_name_attr: self.variable_name_attr, 297 + match_node_attr: self.match_node_attr, 293 298 } 294 299 } 295 300 }
+26
src/execution/lazy.rs
··· 60 60 lazy: config.lazy, 61 61 location_attr: config.location_attr.clone(), 62 62 variable_name_attr: config.variable_name_attr.clone(), 63 + match_node_attr: config.match_node_attr.clone(), 63 64 }; 64 65 65 66 let mut locals = VariableMap::new(); ··· 136 137 locals: &'a mut dyn MutVariables<LazyValue>, 137 138 current_regex_captures: &'a Vec<String>, 138 139 mat: &'a QueryMatch<'a, 'tree>, 140 + full_match_file_capture_index: usize, 139 141 store: &'a mut LazyStore, 140 142 scoped_store: &'a mut LazyScopedVariables, 141 143 lazy_graph: &'a mut LazyGraph, ··· 201 203 locals, 202 204 current_regex_captures: &current_regex_captures, 203 205 mat, 206 + full_match_file_capture_index: self.full_match_file_capture_index, 204 207 store, 205 208 scoped_store, 206 209 lazy_graph, ··· 265 268 let graph_node = exec.graph.add_graph_node(); 266 269 self.node 267 270 .add_debug_attrs(&mut exec.graph[graph_node].attributes, exec.config)?; 271 + if let Some(match_node_attr) = &exec.config.match_node_attr { 272 + let match_node = exec 273 + .mat 274 + .nodes_for_capture_index(exec.full_match_file_capture_index as u32) 275 + .next() 276 + .expect("missing capture for full match"); 277 + let syn_node = exec.graph.add_syntax_node(match_node); 278 + exec.graph[graph_node] 279 + .attributes 280 + .add(match_node_attr.clone(), syn_node) 281 + .map_err(|_| { 282 + ExecutionError::DuplicateAttribute(format!( 283 + " {} on graph node ({}) in {}", 284 + match_node_attr, graph_node, self, 285 + )) 286 + })?; 287 + } 268 288 self.node.add_lazy(exec, graph_node.into(), false) 269 289 } 270 290 } ··· 365 385 locals: &mut arm_locals, 366 386 current_regex_captures: &current_regex_captures, 367 387 mat: exec.mat, 388 + full_match_file_capture_index: exec.full_match_file_capture_index, 368 389 store: exec.store, 369 390 scoped_store: exec.scoped_store, 370 391 lazy_graph: exec.lazy_graph, ··· 431 452 locals: &mut arm_locals, 432 453 current_regex_captures: exec.current_regex_captures, 433 454 mat: exec.mat, 455 + full_match_file_capture_index: exec.full_match_file_capture_index, 434 456 store: exec.store, 435 457 scoped_store: exec.scoped_store, 436 458 lazy_graph: exec.lazy_graph, ··· 478 500 locals: &mut loop_locals, 479 501 current_regex_captures: exec.current_regex_captures, 480 502 mat: exec.mat, 503 + full_match_file_capture_index: exec.full_match_file_capture_index, 481 504 store: exec.store, 482 505 scoped_store: exec.scoped_store, 483 506 lazy_graph: exec.lazy_graph, ··· 572 595 locals: &mut loop_locals, 573 596 current_regex_captures: exec.current_regex_captures, 574 597 mat: exec.mat, 598 + full_match_file_capture_index: exec.full_match_file_capture_index, 575 599 store: exec.store, 576 600 scoped_store: exec.scoped_store, 577 601 lazy_graph: exec.lazy_graph, ··· 615 639 locals: &mut loop_locals, 616 640 current_regex_captures: exec.current_regex_captures, 617 641 mat: exec.mat, 642 + full_match_file_capture_index: exec.full_match_file_capture_index, 618 643 store: exec.store, 619 644 scoped_store: exec.scoped_store, 620 645 lazy_graph: exec.lazy_graph, ··· 830 855 locals: &mut shorthand_locals, 831 856 current_regex_captures: exec.current_regex_captures, 832 857 mat: exec.mat, 858 + full_match_file_capture_index: exec.full_match_file_capture_index, 833 859 store: exec.store, 834 860 scoped_store: exec.scoped_store, 835 861 lazy_graph: exec.lazy_graph,
+26
src/execution/strict.rs
··· 81 81 lazy: config.lazy, 82 82 location_attr: config.location_attr.clone(), 83 83 variable_name_attr: config.variable_name_attr.clone(), 84 + match_node_attr: config.match_node_attr.clone(), 84 85 }; 85 86 86 87 let mut locals = VariableMap::new(); ··· 133 134 current_regex_captures: &'a Vec<String>, 134 135 function_parameters: &'a mut Vec<Value>, 135 136 mat: &'a QueryMatch<'a, 'tree>, 137 + full_match_stanza_capture_index: usize, 136 138 error_context: StatementContext, 137 139 inherited_variables: &'a HashSet<Identifier>, 138 140 shorthands: &'a AttributeShorthands, ··· 192 194 current_regex_captures, 193 195 function_parameters, 194 196 mat: &mat, 197 + full_match_stanza_capture_index: self.full_match_stanza_capture_index, 195 198 error_context, 196 199 inherited_variables, 197 200 shorthands, ··· 283 286 let graph_node = exec.graph.add_graph_node(); 284 287 self.node 285 288 .add_debug_attrs(&mut exec.graph[graph_node].attributes, exec.config)?; 289 + if let Some(match_node_attr) = &exec.config.match_node_attr { 290 + let match_node = exec 291 + .mat 292 + .nodes_for_capture_index(exec.full_match_stanza_capture_index as u32) 293 + .next() 294 + .expect("missing capture for full match"); 295 + let syn_node = exec.graph.add_syntax_node(match_node); 296 + exec.graph[graph_node] 297 + .attributes 298 + .add(match_node_attr.clone(), syn_node) 299 + .map_err(|_| { 300 + ExecutionError::DuplicateAttribute(format!( 301 + " {} on graph node ({}) in {}", 302 + match_node_attr, graph_node, self, 303 + )) 304 + })?; 305 + } 286 306 let value = Value::GraphNode(graph_node); 287 307 self.node.add(exec, value, false) 288 308 } ··· 408 428 current_regex_captures: &current_regex_captures, 409 429 function_parameters: exec.function_parameters, 410 430 mat: exec.mat, 431 + full_match_stanza_capture_index: exec.full_match_stanza_capture_index, 411 432 error_context: exec.error_context.clone(), 412 433 inherited_variables: exec.inherited_variables, 413 434 shorthands: exec.shorthands, ··· 468 489 current_regex_captures: exec.current_regex_captures, 469 490 function_parameters: exec.function_parameters, 470 491 mat: exec.mat, 492 + full_match_stanza_capture_index: exec.full_match_stanza_capture_index, 471 493 error_context: exec.error_context.clone(), 472 494 inherited_variables: exec.inherited_variables, 473 495 shorthands: exec.shorthands, ··· 510 532 current_regex_captures: exec.current_regex_captures, 511 533 function_parameters: exec.function_parameters, 512 534 mat: exec.mat, 535 + full_match_stanza_capture_index: exec.full_match_stanza_capture_index, 513 536 error_context: exec.error_context.clone(), 514 537 inherited_variables: exec.inherited_variables, 515 538 shorthands: exec.shorthands, ··· 585 608 current_regex_captures: exec.current_regex_captures, 586 609 function_parameters: exec.function_parameters, 587 610 mat: exec.mat, 611 + full_match_stanza_capture_index: exec.full_match_stanza_capture_index, 588 612 error_context: exec.error_context.clone(), 589 613 inherited_variables: exec.inherited_variables, 590 614 shorthands: exec.shorthands, ··· 625 649 current_regex_captures: exec.current_regex_captures, 626 650 function_parameters: exec.function_parameters, 627 651 mat: exec.mat, 652 + full_match_stanza_capture_index: exec.full_match_stanza_capture_index, 628 653 error_context: exec.error_context.clone(), 629 654 inherited_variables: exec.inherited_variables, 630 655 shorthands: exec.shorthands, ··· 882 907 current_regex_captures: exec.current_regex_captures, 883 908 function_parameters: exec.function_parameters, 884 909 mat: exec.mat, 910 + full_match_stanza_capture_index: exec.full_match_stanza_capture_index, 885 911 error_context: exec.error_context.clone(), 886 912 inherited_variables: exec.inherited_variables, 887 913 shorthands: exec.shorthands,