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

Use index into the stanza query with strict evaluation

Changed files
+11 -4
src
+2
src/ast.rs
··· 62 62 pub query: Query, 63 63 /// The list of statements in the stanza 64 64 pub statements: Vec<Statement>, 65 + /// Capture index of the full match in the stanza query 66 + pub full_match_stanza_capture_index: usize, 65 67 /// Capture index of the full match in the file query 66 68 pub full_match_file_capture_index: usize, 67 69 pub location: Location,
+1 -1
src/execution/strict.rs
··· 174 174 let node = mat 175 175 .captures 176 176 .iter() 177 - .find(|c| c.index as usize == self.full_match_file_capture_index) 177 + .find(|c| c.index as usize == self.full_match_stanza_capture_index) 178 178 .unwrap() 179 179 .node; 180 180 Context::Statement {
+8 -3
src/parser.rs
··· 276 276 277 277 fn parse_stanza(&mut self, language: Language) -> Result<ast::Stanza, ParseError> { 278 278 let location = self.location; 279 - let query = self.parse_query(language)?; 279 + let (query, full_match_stanza_capture_index) = self.parse_query(language)?; 280 280 self.consume_whitespace(); 281 281 let statements = self.parse_statements()?; 282 282 Ok(ast::Stanza { 283 283 query, 284 284 statements, 285 + full_match_stanza_capture_index, 285 286 full_match_file_capture_index: usize::MAX, // set in checker 286 287 location, 287 288 }) 288 289 } 289 290 290 - fn parse_query(&mut self, language: Language) -> Result<Query, ParseError> { 291 + fn parse_query(&mut self, language: Language) -> Result<(Query, usize), ParseError> { 291 292 let location = self.location; 292 293 let query_start = self.offset; 293 294 self.skip_query()?; ··· 311 312 if query.pattern_count() > 1 { 312 313 return Err(ParseError::UnexpectedQueryPatterns(location)); 313 314 } 314 - Ok(query) 315 + let full_match_capture_index = query 316 + .capture_index_for_name(FULL_MATCH) 317 + .expect("missing capture index for full match") 318 + as usize; 319 + Ok((query, full_match_capture_index)) 315 320 } 316 321 317 322 fn skip_query(&mut self) -> Result<(), ParseError> {