+4
CHANGELOG.md
+4
CHANGELOG.md
···
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
8
+
## v0.12.0 -- 2024-12-12
9
+
10
+
Upgraded the `tree-sitter` dependency to version 0.24.
11
+
12
## v0.11.3 -- 2024-05-29
13
14
### Library
+6
-6
Cargo.toml
+6
-6
Cargo.toml
···
1
[package]
2
name = "tree-sitter-graph"
3
-
version = "0.11.3"
4
description = "Construct graphs from parsed source code"
5
homepage = "https://github.com/tree-sitter/tree-sitter-graph/"
6
repository = "https://github.com/tree-sitter/tree-sitter-graph/"
···
33
serde = "1.0"
34
serde_json = "1.0"
35
smallvec = { version="1.6", features=["union"] }
36
-
string-interner = { version = "0.12", default-features = false, features = ["std", "inline-more", "backends"] }
37
thiserror = "1.0.7"
38
-
tree-sitter = "0.20.3"
39
-
tree-sitter-config = { version = "0.19", optional = true }
40
-
tree-sitter-loader = { version = "0.20", optional = true }
41
42
[dev-dependencies]
43
env_logger = "0.9"
44
indoc = "1.0"
45
-
tree-sitter-python = "0.20"
···
1
[package]
2
name = "tree-sitter-graph"
3
+
version = "0.12.0"
4
description = "Construct graphs from parsed source code"
5
homepage = "https://github.com/tree-sitter/tree-sitter-graph/"
6
repository = "https://github.com/tree-sitter/tree-sitter-graph/"
···
33
serde = "1.0"
34
serde_json = "1.0"
35
smallvec = { version="1.6", features=["union"] }
36
+
streaming-iterator = "0.1.9"
37
thiserror = "1.0.7"
38
+
tree-sitter = "0.24"
39
+
tree-sitter-config = { version = "0.24", optional = true }
40
+
tree-sitter-loader = { version = "0.24", optional = true }
41
42
[dev-dependencies]
43
env_logger = "0.9"
44
indoc = "1.0"
45
+
tree-sitter-python = "=0.23.5"
+1
-1
README.md
+1
-1
README.md
+3
-3
src/bin/tree-sitter-graph/main.rs
+3
-3
src/bin/tree-sitter-graph/main.rs
···
89
)?;
90
}
91
92
-
let config = Config::load()?;
93
let mut loader = Loader::new()?;
94
let loader_config = config.get()?;
95
loader.find_all_languages(&loader_config)?;
···
98
let tsg = std::fs::read(tsg_path)
99
.with_context(|| format!("Cannot read TSG file {}", tsg_path.display()))?;
100
let tsg = String::from_utf8(tsg)?;
101
-
let file = match File::from_str(language, &tsg) {
102
Ok(file) => file,
103
Err(err) => {
104
eprintln!("{}", err.display_pretty(tsg_path, &tsg));
···
110
.with_context(|| format!("Cannot read source file {}", source_path.display()))?;
111
let source = String::from_utf8(source)?;
112
let mut parser = Parser::new();
113
-
parser.set_language(language)?;
114
let tree = parser
115
.parse(&source, None)
116
.ok_or_else(|| anyhow!("Cannot parse {}", source_path.display()))?;
···
89
)?;
90
}
91
92
+
let config = Config::load(None)?;
93
let mut loader = Loader::new()?;
94
let loader_config = config.get()?;
95
loader.find_all_languages(&loader_config)?;
···
98
let tsg = std::fs::read(tsg_path)
99
.with_context(|| format!("Cannot read TSG file {}", tsg_path.display()))?;
100
let tsg = String::from_utf8(tsg)?;
101
+
let file = match File::from_str(language.clone(), &tsg) {
102
Ok(file) => file,
103
Err(err) => {
104
eprintln!("{}", err.display_pretty(tsg_path, &tsg));
···
110
.with_context(|| format!("Cannot read source file {}", source_path.display()))?;
111
let source = String::from_utf8(source)?;
112
let mut parser = Parser::new();
113
+
parser.set_language(&language)?;
114
let tree = parser
115
.parse(&source, None)
116
.ok_or_else(|| anyhow!("Cannot parse {}", source_path.display()))?;
+1
-1
src/checker.rs
+1
-1
src/checker.rs
+10
-10
src/execution.rs
+10
-10
src/execution.rs
···
119
.iter()
120
.map(|name| {
121
let index = file_query
122
-
.capture_index_for_name(name)
123
.expect("missing index for capture");
124
let quantifier =
125
file_query.capture_quantifiers(mat.pattern_index)[index as usize];
126
-
(name, quantifier, index)
127
})
128
.filter(|c| c.2 != stanza.full_match_file_capture_index as u32)
129
.collect();
···
143
.map(|name| {
144
let index = stanza
145
.query
146
-
.capture_index_for_name(name)
147
.expect("missing index for capture");
148
let quantifier = stanza.query.capture_quantifiers(0)[index as usize];
149
-
(name, quantifier, index)
150
})
151
.filter(|c| c.2 != stanza.full_match_stanza_capture_index as u32)
152
.collect();
···
179
.map(|name| {
180
let index = self
181
.query
182
-
.capture_index_for_name(name)
183
.expect("missing index for capture");
184
let quantifier = self.query.capture_quantifiers(0)[index as usize];
185
-
(name, quantifier, index)
186
})
187
.filter(|c| c.2 != self.full_match_stanza_capture_index as u32)
188
.collect();
···
197
}
198
199
pub struct Match<'a, 'tree> {
200
-
mat: QueryMatch<'a, 'tree>,
201
full_capture_index: u32,
202
-
named_captures: Vec<(&'a String, CaptureQuantifier, u32)>,
203
query_location: Location,
204
}
205
···
217
&'s self,
218
) -> impl Iterator<
219
Item = (
220
-
&String,
221
CaptureQuantifier,
222
impl Iterator<Item = Node<'tree>> + 's,
223
),
···
239
}
240
241
/// Return an iterator over all capture names.
242
-
pub fn capture_names(&self) -> impl Iterator<Item = &String> {
243
self.named_captures.iter().map(|c| c.0)
244
}
245
···
119
.iter()
120
.map(|name| {
121
let index = file_query
122
+
.capture_index_for_name(*name)
123
.expect("missing index for capture");
124
let quantifier =
125
file_query.capture_quantifiers(mat.pattern_index)[index as usize];
126
+
(*name, quantifier, index)
127
})
128
.filter(|c| c.2 != stanza.full_match_file_capture_index as u32)
129
.collect();
···
143
.map(|name| {
144
let index = stanza
145
.query
146
+
.capture_index_for_name(*name)
147
.expect("missing index for capture");
148
let quantifier = stanza.query.capture_quantifiers(0)[index as usize];
149
+
(*name, quantifier, index)
150
})
151
.filter(|c| c.2 != stanza.full_match_stanza_capture_index as u32)
152
.collect();
···
179
.map(|name| {
180
let index = self
181
.query
182
+
.capture_index_for_name(*name)
183
.expect("missing index for capture");
184
let quantifier = self.query.capture_quantifiers(0)[index as usize];
185
+
(*name, quantifier, index)
186
})
187
.filter(|c| c.2 != self.full_match_stanza_capture_index as u32)
188
.collect();
···
197
}
198
199
pub struct Match<'a, 'tree> {
200
+
mat: &'a QueryMatch<'a, 'tree>,
201
full_capture_index: u32,
202
+
named_captures: Vec<(&'a str, CaptureQuantifier, u32)>,
203
query_location: Location,
204
}
205
···
217
&'s self,
218
) -> impl Iterator<
219
Item = (
220
+
&'a str,
221
CaptureQuantifier,
222
impl Iterator<Item = Node<'tree>> + 's,
223
),
···
239
}
240
241
/// Return an iterator over all capture names.
242
+
pub fn capture_names(&self) -> impl Iterator<Item = &str> {
243
self.named_captures.iter().map(|c| c.0)
244
}
245
+5
-3
src/execution/lazy.rs
+5
-3
src/execution/lazy.rs
···
18
use tree_sitter::QueryMatch;
19
use tree_sitter::Tree;
20
21
use crate::ast;
22
use crate::execution::error::ExecutionError;
23
use crate::execution::error::ResultWithExecutionError;
···
116
mut visit: F,
117
) -> Result<(), E>
118
where
119
-
F: FnMut(&ast::Stanza, QueryMatch<'_, 'tree>) -> Result<(), E>,
120
{
121
let mut cursor = QueryCursor::new();
122
let query = self.query.as_ref().unwrap();
123
-
let matches = cursor.matches(query, tree.root_node(), source.as_bytes());
124
-
for mat in matches {
125
let stanza = &self.stanzas[mat.pattern_index];
126
visit(stanza, mat)?;
127
}
···
18
use tree_sitter::QueryMatch;
19
use tree_sitter::Tree;
20
21
+
use streaming_iterator::StreamingIterator;
22
+
23
use crate::ast;
24
use crate::execution::error::ExecutionError;
25
use crate::execution::error::ResultWithExecutionError;
···
118
mut visit: F,
119
) -> Result<(), E>
120
where
121
+
F: FnMut(&ast::Stanza, &QueryMatch<'_, 'tree>) -> Result<(), E>,
122
{
123
let mut cursor = QueryCursor::new();
124
let query = self.query.as_ref().unwrap();
125
+
let mut matches = cursor.matches(query, tree.root_node(), source.as_bytes());
126
+
while let Some(mat) = matches.next() {
127
let stanza = &self.stanzas[mat.pattern_index];
128
visit(stanza, mat)?;
129
}
+5
-4
src/execution/strict.rs
+5
-4
src/execution/strict.rs
···
8
use std::collections::BTreeSet;
9
use std::collections::HashMap;
10
use std::collections::HashSet;
11
use tree_sitter::QueryCursor;
12
use tree_sitter::QueryMatch;
13
use tree_sitter::Tree;
···
115
mut visit: F,
116
) -> Result<(), E>
117
where
118
-
F: FnMut(&Stanza, QueryMatch<'_, 'tree>) -> Result<(), E>,
119
{
120
for stanza in &self.stanzas {
121
stanza.try_visit_matches_strict(tree, source, |mat| visit(stanza, mat))?;
···
214
mut visit: F,
215
) -> Result<(), E>
216
where
217
-
F: FnMut(QueryMatch<'_, 'tree>) -> Result<(), E>,
218
{
219
let mut cursor = QueryCursor::new();
220
-
let matches = cursor.matches(&self.query, tree.root_node(), source.as_bytes());
221
-
for mat in matches {
222
visit(mat)?;
223
}
224
Ok(())
···
8
use std::collections::BTreeSet;
9
use std::collections::HashMap;
10
use std::collections::HashSet;
11
+
use streaming_iterator::StreamingIterator;
12
use tree_sitter::QueryCursor;
13
use tree_sitter::QueryMatch;
14
use tree_sitter::Tree;
···
116
mut visit: F,
117
) -> Result<(), E>
118
where
119
+
F: FnMut(&Stanza, &QueryMatch<'_, 'tree>) -> Result<(), E>,
120
{
121
for stanza in &self.stanzas {
122
stanza.try_visit_matches_strict(tree, source, |mat| visit(stanza, mat))?;
···
215
mut visit: F,
216
) -> Result<(), E>
217
where
218
+
F: FnMut(&QueryMatch<'_, 'tree>) -> Result<(), E>,
219
{
220
let mut cursor = QueryCursor::new();
221
+
let mut matches = cursor.matches(&self.query, tree.root_node(), source.as_bytes());
222
+
while let Some(mat) = matches.next() {
223
visit(mat)?;
224
}
225
Ok(())
+1
-1
src/parse_error.rs
+1
-1
src/parse_error.rs
+4
-4
src/parser.rs
+4
-4
src/parser.rs
···
305
let name = self.parse_identifier("inherit")?;
306
file.inherited_variables.insert(name);
307
} else {
308
-
let stanza = self.parse_stanza(file.language)?;
309
file.stanzas.push(stanza);
310
}
311
self.consume_whitespace();
312
}
313
// we can unwrap here because all queries have already been parsed before
314
-
file.query = Some(Query::new(file.language, &self.query_source).unwrap());
315
Ok(())
316
}
317
···
369
Ok(quantifier)
370
}
371
372
-
fn parse_stanza(&mut self, language: Language) -> Result<ast::Stanza, ParseError> {
373
let start = self.location;
374
let (query, full_match_stanza_capture_index) = self.parse_query(language)?;
375
self.consume_whitespace();
···
385
})
386
}
387
388
-
fn parse_query(&mut self, language: Language) -> Result<(Query, usize), ParseError> {
389
let location = self.location;
390
let query_start = self.offset;
391
self.skip_query()?;
···
305
let name = self.parse_identifier("inherit")?;
306
file.inherited_variables.insert(name);
307
} else {
308
+
let stanza = self.parse_stanza(&file.language)?;
309
file.stanzas.push(stanza);
310
}
311
self.consume_whitespace();
312
}
313
// we can unwrap here because all queries have already been parsed before
314
+
file.query = Some(Query::new(&file.language, &self.query_source).unwrap());
315
Ok(())
316
}
317
···
369
Ok(quantifier)
370
}
371
372
+
fn parse_stanza(&mut self, language: &Language) -> Result<ast::Stanza, ParseError> {
373
let start = self.location;
374
let (query, full_match_stanza_capture_index) = self.parse_query(language)?;
375
self.consume_whitespace();
···
385
})
386
}
387
388
+
fn parse_query(&mut self, language: &Language) -> Result<(Query, usize), ParseError> {
389
let location = self.location;
390
let query_start = self.offset;
391
self.skip_query()?;
+4
-2
tests/it/execution.rs
+4
-2
tests/it/execution.rs
···
27
fn execute(python_source: &str, dsl_source: &str) -> Result<String, ExecutionError> {
28
init_log();
29
let mut parser = Parser::new();
30
-
parser.set_language(tree_sitter_python::language()).unwrap();
31
let tree = parser.parse(python_source, None).unwrap();
32
let file =
33
-
File::from_str(tree_sitter_python::language(), dsl_source).expect("Cannot parse file");
34
let functions = Functions::stdlib();
35
let mut globals = Variables::new();
36
globals
···
27
fn execute(python_source: &str, dsl_source: &str) -> Result<String, ExecutionError> {
28
init_log();
29
let mut parser = Parser::new();
30
+
parser
31
+
.set_language(&tree_sitter_python::LANGUAGE.into())
32
+
.unwrap();
33
let tree = parser.parse(python_source, None).unwrap();
34
let file =
35
+
File::from_str(tree_sitter_python::LANGUAGE.into(), dsl_source).expect("Cannot parse file");
36
let functions = Functions::stdlib();
37
let mut globals = Variables::new();
38
globals
+4
-2
tests/it/functions.rs
+4
-2
tests/it/functions.rs
···
27
fn execute(python_source: &str, dsl_source: &str) -> Result<String, ExecutionError> {
28
init_log();
29
let mut parser = Parser::new();
30
-
parser.set_language(tree_sitter_python::language()).unwrap();
31
let tree = parser.parse(python_source, None).unwrap();
32
let file =
33
-
File::from_str(tree_sitter_python::language(), dsl_source).expect("Cannot parse file");
34
let functions = Functions::stdlib();
35
let mut globals = Variables::new();
36
globals
···
27
fn execute(python_source: &str, dsl_source: &str) -> Result<String, ExecutionError> {
28
init_log();
29
let mut parser = Parser::new();
30
+
parser
31
+
.set_language(&tree_sitter_python::LANGUAGE.into())
32
+
.unwrap();
33
let tree = parser.parse(python_source, None).unwrap();
34
let file =
35
+
File::from_str(tree_sitter_python::LANGUAGE.into(), dsl_source).expect("Cannot parse file");
36
let functions = Functions::stdlib();
37
let mut globals = Variables::new();
38
globals
+3
-1
tests/it/graph.rs
+3
-1
tests/it/graph.rs
+4
-2
tests/it/lazy_execution.rs
+4
-2
tests/it/lazy_execution.rs
···
26
fn execute(python_source: &str, dsl_source: &str) -> Result<String, ExecutionError> {
27
init_log();
28
let mut parser = Parser::new();
29
-
parser.set_language(tree_sitter_python::language()).unwrap();
30
let tree = parser.parse(python_source, None).unwrap();
31
let file =
32
-
File::from_str(tree_sitter_python::language(), dsl_source).expect("Cannot parse file");
33
let functions = Functions::stdlib();
34
let mut globals = Variables::new();
35
globals
···
26
fn execute(python_source: &str, dsl_source: &str) -> Result<String, ExecutionError> {
27
init_log();
28
let mut parser = Parser::new();
29
+
parser
30
+
.set_language(&tree_sitter_python::LANGUAGE.into())
31
+
.unwrap();
32
let tree = parser.parse(python_source, None).unwrap();
33
let file =
34
+
File::from_str(tree_sitter_python::LANGUAGE.into(), dsl_source).expect("Cannot parse file");
35
let functions = Functions::stdlib();
36
let mut globals = Variables::new();
37
globals
+3
-1
tests/it/parse_errors.rs
+3
-1
tests/it/parse_errors.rs
+64
-39
tests/it/parser.rs
+64
-39
tests/it/parser.rs
···
27
set @cap2.var1 = loc1
28
}
29
"#;
30
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
31
32
let loc1 = Identifier::from("loc1");
33
let precedence = Identifier::from("precedence");
···
228
let t = #true
229
}
230
"#;
231
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
232
233
let f = Identifier::from("f");
234
let n = Identifier::from("n");
···
284
let loc1 = "\"abc,\ndef\\"
285
}
286
"#;
287
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
288
289
let loc1 = Identifier::from("loc1");
290
···
318
let list3 = ["hello", "world",]
319
}
320
"#;
321
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
322
323
let list1 = Identifier::from("list1");
324
let list2 = Identifier::from("list2");
···
395
let set3 = {"hello", "world",}
396
}
397
"#;
398
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
399
400
let set1 = Identifier::from("set1");
401
let set2 = Identifier::from("set2");
···
470
print "x =", 5
471
}
472
"#;
473
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
474
475
let statements = file
476
.stanzas
···
505
node n
506
}
507
"#;
508
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
509
panic!("Parse succeeded unexpectedly");
510
}
511
}
···
518
print @stmts
519
}
520
"#;
521
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
522
523
let stmts = Identifier::from("stmts");
524
···
553
print @stmts
554
}
555
"#;
556
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
557
558
let stmt = Identifier::from("stmt");
559
let stmts = Identifier::from("stmts");
···
602
print @stmts
603
}
604
"#;
605
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
606
607
let stmts = Identifier::from("stmts");
608
···
636
print @stmt
637
}
638
"#;
639
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
640
641
let stmt = Identifier::from("stmt");
642
···
670
print @stmt
671
}
672
"#;
673
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
674
675
let stmt = Identifier::from("stmt");
676
···
704
print @stmt
705
}
706
"#;
707
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
708
709
let stmt = Identifier::from("stmt");
710
···
738
print @stmt
739
}
740
"#;
741
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
742
743
let stmt = Identifier::from("stmt");
744
···
774
}
775
}
776
"#;
777
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
778
779
let x = Identifier::from("x");
780
···
826
}
827
}
828
"#;
829
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
830
831
let x = Identifier::from("x");
832
···
903
}
904
}
905
"#;
906
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
907
908
let x = Identifier::from("x");
909
···
967
}
968
}
969
"#;
970
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
971
panic!("Parse succeeded unexpectedly");
972
}
973
}
···
982
}
983
}
984
"#;
985
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
986
987
let xs = Identifier::from("xs");
988
let x = Identifier::from("x");
···
1032
}
1033
}
1034
"#;
1035
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1036
panic!("Parse succeeded unexpectedly");
1037
}
1038
}
···
1051
}
1052
}
1053
"#;
1054
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1055
panic!("Parse succeeded unexpectedly");
1056
}
1057
}
···
1071
}
1072
}
1073
"#;
1074
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1075
panic!("Parse succeeded unexpectedly");
1076
}
1077
}
···
1084
print [ (named-child-index x) for x in @xs ]
1085
}
1086
"#;
1087
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
1088
1089
let statements = file
1090
.stanzas
···
1137
print { (named-child-index x) for x in @xs }
1138
}
1139
"#;
1140
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
1141
1142
let statements = file
1143
.stanzas
···
1192
edge n -> root
1193
}
1194
"#;
1195
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
1196
1197
assert_eq!(
1198
file.globals,
···
1248
print PKG_NAME
1249
}
1250
"#;
1251
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
1252
1253
assert_eq!(
1254
file.globals,
···
1287
edge n -> root
1288
}
1289
"#;
1290
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1291
panic!("Parse succeeded unexpectedly");
1292
}
1293
}
···
1304
}
1305
}
1306
"#;
1307
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
1308
1309
assert_eq!(
1310
file.globals,
···
1377
}
1378
}
1379
"#;
1380
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
1381
1382
assert_eq!(
1383
file.globals,
···
1448
node root
1449
}
1450
"#;
1451
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1452
panic!("Parse succeeded unexpectedly");
1453
}
1454
}
···
1462
node root
1463
}
1464
"#;
1465
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1466
panic!("Parse succeeded unexpectedly");
1467
}
1468
}
···
1476
set root = #null
1477
}
1478
"#;
1479
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1480
panic!("Parse succeeded unexpectedly");
1481
}
1482
}
···
1490
attr (n) sh = @name
1491
}
1492
"#;
1493
-
let file = File::from_str(tree_sitter_python::language(), source).expect("Cannot parse file");
1494
1495
let shorthands = file.shorthands.into_iter().collect::<Vec<_>>();
1496
assert_eq!(
···
1536
{
1537
}
1538
"#;
1539
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1540
panic!("Parse succeeded unexpectedly");
1541
}
1542
}
···
1548
(module (non_existing_node))
1549
{}
1550
"#;
1551
-
let err = match File::from_str(tree_sitter_python::language(), source) {
1552
Ok(_) => panic!("Parse succeeded unexpectedly"),
1553
Err(ParseError::QueryError(e)) => e,
1554
Err(e) => panic!("Unexpected error: {}", e),
···
1570
]
1571
{}
1572
"#;
1573
-
let err = match File::from_str(tree_sitter_python::language(), source) {
1574
Ok(_) => panic!("Parse succeeded unexpectedly"),
1575
Err(ParseError::QueryError(e)) => e,
1576
Err(e) => panic!("Unexpected error: {}", e),
···
1586
(function_definition name: (identifier) @name) {
1587
}
1588
"#;
1589
-
if let Ok(_) = File::from_str(tree_sitter_python::language(), source) {
1590
panic!("Parse succeeded unexpectedly");
1591
}
1592
}
···
1597
(function_definition name: (identifier) @_name) {
1598
}
1599
"#;
1600
-
File::from_str(tree_sitter_python::language(), source).expect("parse to succeed");
1601
}
1602
1603
#[test]
···
1605
let source = r#"
1606
inherit .scope
1607
"#;
1608
-
let file = File::from_str(tree_sitter_python::language(), source).expect("parse to succeed");
1609
assert!(file.inherited_variables.contains("scope".into()));
1610
}
···
27
set @cap2.var1 = loc1
28
}
29
"#;
30
+
let file =
31
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
32
33
let loc1 = Identifier::from("loc1");
34
let precedence = Identifier::from("precedence");
···
229
let t = #true
230
}
231
"#;
232
+
let file =
233
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
234
235
let f = Identifier::from("f");
236
let n = Identifier::from("n");
···
286
let loc1 = "\"abc,\ndef\\"
287
}
288
"#;
289
+
let file =
290
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
291
292
let loc1 = Identifier::from("loc1");
293
···
321
let list3 = ["hello", "world",]
322
}
323
"#;
324
+
let file =
325
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
326
327
let list1 = Identifier::from("list1");
328
let list2 = Identifier::from("list2");
···
399
let set3 = {"hello", "world",}
400
}
401
"#;
402
+
let file =
403
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
404
405
let set1 = Identifier::from("set1");
406
let set2 = Identifier::from("set2");
···
475
print "x =", 5
476
}
477
"#;
478
+
let file =
479
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
480
481
let statements = file
482
.stanzas
···
511
node n
512
}
513
"#;
514
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
515
panic!("Parse succeeded unexpectedly");
516
}
517
}
···
524
print @stmts
525
}
526
"#;
527
+
let file =
528
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
529
530
let stmts = Identifier::from("stmts");
531
···
560
print @stmts
561
}
562
"#;
563
+
let file =
564
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
565
566
let stmt = Identifier::from("stmt");
567
let stmts = Identifier::from("stmts");
···
610
print @stmts
611
}
612
"#;
613
+
let file =
614
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
615
616
let stmts = Identifier::from("stmts");
617
···
645
print @stmt
646
}
647
"#;
648
+
let file =
649
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
650
651
let stmt = Identifier::from("stmt");
652
···
680
print @stmt
681
}
682
"#;
683
+
let file =
684
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
685
686
let stmt = Identifier::from("stmt");
687
···
715
print @stmt
716
}
717
"#;
718
+
let file =
719
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
720
721
let stmt = Identifier::from("stmt");
722
···
750
print @stmt
751
}
752
"#;
753
+
let file =
754
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
755
756
let stmt = Identifier::from("stmt");
757
···
787
}
788
}
789
"#;
790
+
let file =
791
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
792
793
let x = Identifier::from("x");
794
···
840
}
841
}
842
"#;
843
+
let file =
844
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
845
846
let x = Identifier::from("x");
847
···
918
}
919
}
920
"#;
921
+
let file =
922
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
923
924
let x = Identifier::from("x");
925
···
983
}
984
}
985
"#;
986
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
987
panic!("Parse succeeded unexpectedly");
988
}
989
}
···
998
}
999
}
1000
"#;
1001
+
let file =
1002
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1003
1004
let xs = Identifier::from("xs");
1005
let x = Identifier::from("x");
···
1049
}
1050
}
1051
"#;
1052
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1053
panic!("Parse succeeded unexpectedly");
1054
}
1055
}
···
1068
}
1069
}
1070
"#;
1071
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1072
panic!("Parse succeeded unexpectedly");
1073
}
1074
}
···
1088
}
1089
}
1090
"#;
1091
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1092
panic!("Parse succeeded unexpectedly");
1093
}
1094
}
···
1101
print [ (named-child-index x) for x in @xs ]
1102
}
1103
"#;
1104
+
let file =
1105
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1106
1107
let statements = file
1108
.stanzas
···
1155
print { (named-child-index x) for x in @xs }
1156
}
1157
"#;
1158
+
let file =
1159
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1160
1161
let statements = file
1162
.stanzas
···
1211
edge n -> root
1212
}
1213
"#;
1214
+
let file =
1215
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1216
1217
assert_eq!(
1218
file.globals,
···
1268
print PKG_NAME
1269
}
1270
"#;
1271
+
let file =
1272
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1273
1274
assert_eq!(
1275
file.globals,
···
1308
edge n -> root
1309
}
1310
"#;
1311
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1312
panic!("Parse succeeded unexpectedly");
1313
}
1314
}
···
1325
}
1326
}
1327
"#;
1328
+
let file =
1329
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1330
1331
assert_eq!(
1332
file.globals,
···
1399
}
1400
}
1401
"#;
1402
+
let file =
1403
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1404
1405
assert_eq!(
1406
file.globals,
···
1471
node root
1472
}
1473
"#;
1474
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1475
panic!("Parse succeeded unexpectedly");
1476
}
1477
}
···
1485
node root
1486
}
1487
"#;
1488
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1489
panic!("Parse succeeded unexpectedly");
1490
}
1491
}
···
1499
set root = #null
1500
}
1501
"#;
1502
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1503
panic!("Parse succeeded unexpectedly");
1504
}
1505
}
···
1513
attr (n) sh = @name
1514
}
1515
"#;
1516
+
let file =
1517
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("Cannot parse file");
1518
1519
let shorthands = file.shorthands.into_iter().collect::<Vec<_>>();
1520
assert_eq!(
···
1560
{
1561
}
1562
"#;
1563
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1564
panic!("Parse succeeded unexpectedly");
1565
}
1566
}
···
1572
(module (non_existing_node))
1573
{}
1574
"#;
1575
+
let err = match File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1576
Ok(_) => panic!("Parse succeeded unexpectedly"),
1577
Err(ParseError::QueryError(e)) => e,
1578
Err(e) => panic!("Unexpected error: {}", e),
···
1594
]
1595
{}
1596
"#;
1597
+
let err = match File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1598
Ok(_) => panic!("Parse succeeded unexpectedly"),
1599
Err(ParseError::QueryError(e)) => e,
1600
Err(e) => panic!("Unexpected error: {}", e),
···
1610
(function_definition name: (identifier) @name) {
1611
}
1612
"#;
1613
+
if let Ok(_) = File::from_str(tree_sitter_python::LANGUAGE.into(), source) {
1614
panic!("Parse succeeded unexpectedly");
1615
}
1616
}
···
1621
(function_definition name: (identifier) @_name) {
1622
}
1623
"#;
1624
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("parse to succeed");
1625
}
1626
1627
#[test]
···
1629
let source = r#"
1630
inherit .scope
1631
"#;
1632
+
let file =
1633
+
File::from_str(tree_sitter_python::LANGUAGE.into(), source).expect("parse to succeed");
1634
assert!(file.inherited_variables.contains("scope".into()));
1635
}
+6
vscode/CHANGELOG.md
+6
vscode/CHANGELOG.md
···
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
8
+
## 0.1.2 -- 2023-12-12
9
+
10
+
### Added
11
+
12
+
- Add missing `else` keyword
13
+
14
## 0.1.1 -- 2023-06-01
15
16
### Added