···55The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7788+## v0.12.0 -- 2024-12-12
99+1010+Upgraded the `tree-sitter` dependency to version 0.24.
1111+812## v0.11.3 -- 2024-05-29
9131014### Library
···20202121``` toml
2222[dependencies]
2323-tree-sitter-graph = "0.11"
2323+tree-sitter-graph = "0.12"
2424```
25252626To use it as a program, install it via `cargo install`:
+3-3
src/bin/tree-sitter-graph/main.rs
···8989 )?;
9090 }
91919292- let config = Config::load()?;
9292+ let config = Config::load(None)?;
9393 let mut loader = Loader::new()?;
9494 let loader_config = config.get()?;
9595 loader.find_all_languages(&loader_config)?;
···9898 let tsg = std::fs::read(tsg_path)
9999 .with_context(|| format!("Cannot read TSG file {}", tsg_path.display()))?;
100100 let tsg = String::from_utf8(tsg)?;
101101- let file = match File::from_str(language, &tsg) {
101101+ let file = match File::from_str(language.clone(), &tsg) {
102102 Ok(file) => file,
103103 Err(err) => {
104104 eprintln!("{}", err.display_pretty(tsg_path, &tsg));
···110110 .with_context(|| format!("Cannot read source file {}", source_path.display()))?;
111111 let source = String::from_utf8(source)?;
112112 let mut parser = Parser::new();
113113- parser.set_language(language)?;
113113+ parser.set_language(&language)?;
114114 let tree = parser
115115 .parse(&source, None)
116116 .ok_or_else(|| anyhow!("Cannot parse {}", source_path.display()))?;
+1-1
src/checker.rs
···188188 .expect("capture should have index")
189189 != self.full_match_stanza_capture_index as u32
190190 })
191191- .map(|cn| Identifier::from(cn.as_str()))
191191+ .map(|cn| Identifier::from(*cn))
192192 .collect::<HashSet<_>>();
193193 let unused_captures = all_captures
194194 .difference(&used_captures)
+10-10
src/execution.rs
···119119 .iter()
120120 .map(|name| {
121121 let index = file_query
122122- .capture_index_for_name(name)
122122+ .capture_index_for_name(*name)
123123 .expect("missing index for capture");
124124 let quantifier =
125125 file_query.capture_quantifiers(mat.pattern_index)[index as usize];
126126- (name, quantifier, index)
126126+ (*name, quantifier, index)
127127 })
128128 .filter(|c| c.2 != stanza.full_match_file_capture_index as u32)
129129 .collect();
···143143 .map(|name| {
144144 let index = stanza
145145 .query
146146- .capture_index_for_name(name)
146146+ .capture_index_for_name(*name)
147147 .expect("missing index for capture");
148148 let quantifier = stanza.query.capture_quantifiers(0)[index as usize];
149149- (name, quantifier, index)
149149+ (*name, quantifier, index)
150150 })
151151 .filter(|c| c.2 != stanza.full_match_stanza_capture_index as u32)
152152 .collect();
···179179 .map(|name| {
180180 let index = self
181181 .query
182182- .capture_index_for_name(name)
182182+ .capture_index_for_name(*name)
183183 .expect("missing index for capture");
184184 let quantifier = self.query.capture_quantifiers(0)[index as usize];
185185- (name, quantifier, index)
185185+ (*name, quantifier, index)
186186 })
187187 .filter(|c| c.2 != self.full_match_stanza_capture_index as u32)
188188 .collect();
···197197}
198198199199pub struct Match<'a, 'tree> {
200200- mat: QueryMatch<'a, 'tree>,
200200+ mat: &'a QueryMatch<'a, 'tree>,
201201 full_capture_index: u32,
202202- named_captures: Vec<(&'a String, CaptureQuantifier, u32)>,
202202+ named_captures: Vec<(&'a str, CaptureQuantifier, u32)>,
203203 query_location: Location,
204204}
205205···217217 &'s self,
218218 ) -> impl Iterator<
219219 Item = (
220220- &String,
220220+ &'a str,
221221 CaptureQuantifier,
222222 impl Iterator<Item = Node<'tree>> + 's,
223223 ),
···239239 }
240240241241 /// Return an iterator over all capture names.
242242- pub fn capture_names(&self) -> impl Iterator<Item = &String> {
242242+ pub fn capture_names(&self) -> impl Iterator<Item = &str> {
243243 self.named_captures.iter().map(|c| c.0)
244244 }
245245
+5-3
src/execution/lazy.rs
···1818use tree_sitter::QueryMatch;
1919use tree_sitter::Tree;
20202121+use streaming_iterator::StreamingIterator;
2222+2123use crate::ast;
2224use crate::execution::error::ExecutionError;
2325use crate::execution::error::ResultWithExecutionError;
···116118 mut visit: F,
117119 ) -> Result<(), E>
118120 where
119119- F: FnMut(&ast::Stanza, QueryMatch<'_, 'tree>) -> Result<(), E>,
121121+ F: FnMut(&ast::Stanza, &QueryMatch<'_, 'tree>) -> Result<(), E>,
120122 {
121123 let mut cursor = QueryCursor::new();
122124 let query = self.query.as_ref().unwrap();
123123- let matches = cursor.matches(query, tree.root_node(), source.as_bytes());
124124- for mat in matches {
125125+ let mut matches = cursor.matches(query, tree.root_node(), source.as_bytes());
126126+ while let Some(mat) = matches.next() {
125127 let stanza = &self.stanzas[mat.pattern_index];
126128 visit(stanza, mat)?;
127129 }
···2727 set @cap2.var1 = loc1
2828 }
2929 "#;
3030- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
3030+ let file =
3131+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
31323233 let loc1 = Identifier::from("loc1");
3334 let precedence = Identifier::from("precedence");
···228229 let t = #true
229230 }
230231 "#;
231231- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
232232+ let file =
233233+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
232234233235 let f = Identifier::from("f");
234236 let n = Identifier::from("n");
···284286 let loc1 = "\"abc,\ndef\\"
285287 }
286288 "#;
287287- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
289289+ let file =
290290+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
288291289292 let loc1 = Identifier::from("loc1");
290293···318321 let list3 = ["hello", "world",]
319322 }
320323 "#;
321321- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
324324+ let file =
325325+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
322326323327 let list1 = Identifier::from("list1");
324328 let list2 = Identifier::from("list2");
···395399 let set3 = {"hello", "world",}
396400 }
397401 "#;
398398- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
402402+ let file =
403403+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
399404400405 let set1 = Identifier::from("set1");
401406 let set2 = Identifier::from("set2");
···470475 print "x =", 5
471476 }
472477 "#;
473473- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
478478+ let file =
479479+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
474480475481 let statements = file
476482 .stanzas
···505511 node n
506512 }
507513 "#;
508508- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
514514+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
509515 panic!("Parse succeeded unexpectedly");
510516 }
511517}
···518524 print @stmts
519525 }
520526 "#;
521521- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
527527+ let file =
528528+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
522529523530 let stmts = Identifier::from("stmts");
524531···553560 print @stmts
554561 }
555562 "#;
556556- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
563563+ let file =
564564+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
557565558566 let stmt = Identifier::from("stmt");
559567 let stmts = Identifier::from("stmts");
···602610 print @stmts
603611 }
604612 "#;
605605- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
613613+ let file =
614614+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
606615607616 let stmts = Identifier::from("stmts");
608617···636645 print @stmt
637646 }
638647 "#;
639639- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
648648+ let file =
649649+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
640650641651 let stmt = Identifier::from("stmt");
642652···670680 print @stmt
671681 }
672682 "#;
673673- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
683683+ let file =
684684+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
674685675686 let stmt = Identifier::from("stmt");
676687···704715 print @stmt
705716 }
706717 "#;
707707- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
718718+ let file =
719719+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
708720709721 let stmt = Identifier::from("stmt");
710722···738750 print @stmt
739751 }
740752 "#;
741741- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
753753+ let file =
754754+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
742755743756 let stmt = Identifier::from("stmt");
744757···774787 }
775788 }
776789 "#;
777777- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
790790+ let file =
791791+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
778792779793 let x = Identifier::from("x");
780794···826840 }
827841 }
828842 "#;
829829- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
843843+ let file =
844844+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
830845831846 let x = Identifier::from("x");
832847···903918 }
904919 }
905920 "#;
906906- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
921921+ let file =
922922+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
907923908924 let x = Identifier::from("x");
909925···967983 }
968984 }
969985 "#;
970970- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
986986+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
971987 panic!("Parse succeeded unexpectedly");
972988 }
973989}
···982998 }
983999 }
9841000 "#;
985985- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
10011001+ let file =
10021002+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
98610039871004 let xs = Identifier::from("xs");
9881005 let x = Identifier::from("x");
···10321049 }
10331050 }
10341051 "#;
10351035- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
10521052+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
10361053 panic!("Parse succeeded unexpectedly");
10371054 }
10381055}
···10511068 }
10521069 }
10531070 "#;
10541054- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
10711071+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
10551072 panic!("Parse succeeded unexpectedly");
10561073 }
10571074}
···10711088 }
10721089 }
10731090 "#;
10741074- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
10911091+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
10751092 panic!("Parse succeeded unexpectedly");
10761093 }
10771094}
···10841101 print [ (named-child-index x) for x in @xs ]
10851102 }
10861103 "#;
10871087- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
11041104+ let file =
11051105+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1088110610891107 let statements = file
10901108 .stanzas
···11371155 print { (named-child-index x) for x in @xs }
11381156 }
11391157 "#;
11401140- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
11581158+ let file =
11591159+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1141116011421161 let statements = file
11431162 .stanzas
···11921211 edge n -> root
11931212 }
11941213 "#;
11951195- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
12141214+ let file =
12151215+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1196121611971217 assert_eq!(
11981218 file.globals,
···12481268 print PKG_NAME
12491269 }
12501270 "#;
12511251- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
12711271+ let file =
12721272+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1252127312531274 assert_eq!(
12541275 file.globals,
···12871308 edge n -> root
12881309 }
12891310 "#;
12901290- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
13111311+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
12911312 panic!("Parse succeeded unexpectedly");
12921313 }
12931314}
···13041325 }
13051326 }
13061327 "#;
13071307- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
13281328+ let file =
13291329+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1308133013091331 assert_eq!(
13101332 file.globals,
···13771399 }
13781400 }
13791401 "#;
13801380- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
14021402+ let file =
14031403+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1381140413821405 assert_eq!(
13831406 file.globals,
···14481471 node root
14491472 }
14501473 "#;
14511451- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
14741474+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
14521475 panic!("Parse succeeded unexpectedly");
14531476 }
14541477}
···14621485 node root
14631486 }
14641487 "#;
14651465- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
14881488+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
14661489 panic!("Parse succeeded unexpectedly");
14671490 }
14681491}
···14761499 set root = #null
14771500 }
14781501 "#;
14791479- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
15021502+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
14801503 panic!("Parse succeeded unexpectedly");
14811504 }
14821505}
···14901513 attr (n) sh = @name
14911514 }
14921515 "#;
14931493- let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
15161516+ let file =
15171517+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1494151814951519 let shorthands = file.shorthands.into_iter().collect::<Vec<_>>();
14961520 assert_eq!(
···15361560 {
15371561 }
15381562 "#;
15391539- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
15631563+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
15401564 panic!("Parse succeeded unexpectedly");
15411565 }
15421566}
···15481572 (module (non_existing_node))
15491573 {}
15501574 "#;
15511551- let err = match File::from_str(tree_sitter_python::language(), source) {
15751575+ let err = match File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
15521576 Ok(_) => panic!("Parse succeeded unexpectedly"),
15531577 Err(ParseError::QueryError(e)) => e,
15541578 Err(e) => panic!("Unexpected error: {}", e),
···15701594 ]
15711595 {}
15721596 "#;
15731573- let err = match File::from_str(tree_sitter_python::language(), source) {
15971597+ let err = match File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
15741598 Ok(_) => panic!("Parse succeeded unexpectedly"),
15751599 Err(ParseError::QueryError(e)) => e,
15761600 Err(e) => panic!("Unexpected error: {}", e),
···15861610 (function_definition name: (identifier) @name) {
15871611 }
15881612 "#;
15891589- if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
16131613+ if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
15901614 panic!("Parse succeeded unexpectedly");
15911615 }
15921616}
···15971621 (function_definition name: (identifier) @_name) {
15981622 }
15991623 "#;
16001600- File::from_str(tree_sitter_python::language(), source).expect("parse to succeed");
16241624+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("parse to succeed");
16011625}
1602162616031627#[test]
···16051629 let source = r#"
16061630 inherit .scope
16071631 "#;
16081608- let file = File::from_str(tree_sitter_python::language(), source).expect("parse to succeed");
16321632+ let file =
16331633+ File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("parse to succeed");
16091634 assert!(file.inherited_variables.contains("scope".into()));
16101635}
+6
vscode/CHANGELOG.md
···55The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7788+## 0.1.2 -- 2023-12-12
99+1010+### Added
1111+1212+- Add missing `else` keyword
1313+814## 0.1.1 -- 2023-06-01
9151016### Added