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

Configure Feed

Select the types of activity you want to include in your feed.

Include quantifier with match

+20 -11
+20 -11
src/execution.rs
··· 118 118 let index = file_query 119 119 .capture_index_for_name(name) 120 120 .expect("missing index for capture"); 121 - (name, index) 121 + let quantifier = file_query.capture_quantifiers(0)[index as usize]; 122 + (name, quantifier, index) 122 123 }) 123 - .filter(|c| c.1 != stanza.full_match_file_capture_index as u32) 124 + .filter(|c| c.2 != stanza.full_match_file_capture_index as u32) 124 125 .collect(); 125 126 visit(Match { 126 127 mat, ··· 140 141 .query 141 142 .capture_index_for_name(name) 142 143 .expect("missing index for capture"); 143 - (name, index) 144 + let quantifier = stanza.query.capture_quantifiers(0)[index as usize]; 145 + (name, quantifier, index) 144 146 }) 145 - .filter(|c| c.1 != stanza.full_match_stanza_capture_index as u32) 147 + .filter(|c| c.2 != stanza.full_match_stanza_capture_index as u32) 146 148 .collect(); 147 149 visit(Match { 148 150 mat, ··· 175 177 .query 176 178 .capture_index_for_name(name) 177 179 .expect("missing index for capture"); 178 - (name, index) 180 + let quantifier = self.query.capture_quantifiers(0)[index as usize]; 181 + (name, quantifier, index) 179 182 }) 180 - .filter(|c| c.1 != self.full_match_stanza_capture_index as u32) 183 + .filter(|c| c.2 != self.full_match_stanza_capture_index as u32) 181 184 .collect(); 182 185 visit(Match { 183 186 mat, ··· 192 195 pub struct Match<'a, 'tree> { 193 196 mat: QueryMatch<'a, 'tree>, 194 197 full_capture_index: u32, 195 - named_captures: Vec<(&'a String, u32)>, 198 + named_captures: Vec<(&'a String, CaptureQuantifier, u32)>, 196 199 query_location: Location, 197 200 } 198 201 ··· 208 211 /// Return the matched nodes for a named capture. 209 212 pub fn named_captures<'s: 'a + 'tree>( 210 213 &'s self, 211 - ) -> impl Iterator<Item = (&String, impl Iterator<Item = Node<'tree>> + 's)> { 214 + ) -> impl Iterator< 215 + Item = ( 216 + &String, 217 + CaptureQuantifier, 218 + impl Iterator<Item = Node<'tree>> + 's, 219 + ), 220 + > { 212 221 self.named_captures 213 222 .iter() 214 - .map(move |c| (c.0, self.mat.nodes_for_capture_index(c.1))) 223 + .map(move |c| (c.0, c.1, self.mat.nodes_for_capture_index(c.2))) 215 224 } 216 225 217 226 /// Return the matched nodes for a named capture. 218 227 pub fn named_capture<'s: 'a + 'tree>( 219 228 &'s self, 220 229 name: &str, 221 - ) -> Option<impl Iterator<Item = Node<'tree>> + 's> { 230 + ) -> Option<(CaptureQuantifier, impl Iterator<Item = Node<'tree>> + 's)> { 222 231 self.named_captures 223 232 .iter() 224 233 .find(|c| c.0 == name) 225 - .map(|c| self.mat.nodes_for_capture_index(c.1)) 234 + .map(|c| (c.1, self.mat.nodes_for_capture_index(c.2))) 226 235 } 227 236 228 237 /// Return an iterator over all capture names.