+2
-1
src/ast.rs
+2
-1
src/ast.rs
···
14
14
use tree_sitter::Language;
15
15
use tree_sitter::Query;
16
16
17
+
use crate::parser::Range;
17
18
use crate::Identifier;
18
19
use crate::Location;
19
20
···
66
67
pub full_match_stanza_capture_index: usize,
67
68
/// Capture index of the full match in the file query
68
69
pub full_match_file_capture_index: usize,
69
-
pub location: Location,
70
+
pub range: Range,
70
71
}
71
72
72
73
/// A statement that can appear in a graph DSL stanza
+1
-1
src/checker.rs
+1
-1
src/checker.rs
+3
-3
src/execution.rs
+3
-3
src/execution.rs
···
126
126
mat,
127
127
full_capture_index: stanza.full_match_file_capture_index as u32,
128
128
named_captures,
129
-
query_location: stanza.location,
129
+
query_location: stanza.range.start,
130
130
})
131
131
})
132
132
} else {
···
148
148
mat,
149
149
full_capture_index: stanza.full_match_stanza_capture_index as u32,
150
150
named_captures,
151
-
query_location: stanza.location,
151
+
query_location: stanza.range.start,
152
152
})
153
153
})
154
154
}
···
183
183
mat,
184
184
full_capture_index: self.full_match_stanza_capture_index as u32,
185
185
named_captures,
186
-
query_location: self.location,
186
+
query_location: self.range.start,
187
187
})
188
188
})
189
189
}
+1
-1
src/execution/error.rs
+1
-1
src/execution/error.rs
···
95
95
Self {
96
96
statement: format!("{}", stmt),
97
97
statement_location: stmt.location(),
98
-
stanza_location: stanza.location,
98
+
stanza_location: stanza.range.start,
99
99
source_location: Location::from(source_node.range().start_point),
100
100
node_kind: source_node.kind().to_string(),
101
101
}
+1
-1
src/execution/lazy.rs
+1
-1
src/execution/lazy.rs
···
185
185
.nodes_for_capture_index(self.full_match_file_capture_index as u32)
186
186
.next()
187
187
.expect("missing capture for full match");
188
-
debug!("match {:?} at {}", node, self.location);
188
+
debug!("match {:?} at {}", node, self.range.start);
189
189
trace!("{{");
190
190
for statement in &self.statements {
191
191
let error_context = { StatementContext::new(&statement, &self, &node) };
+21
-4
src/parser.rs
+21
-4
src/parser.rs
···
7
7
8
8
use std::fmt::Display;
9
9
use std::iter::Peekable;
10
-
use std::ops::Range;
11
10
use std::path::Path;
12
11
use std::str::Chars;
13
12
···
161
160
}
162
161
}
163
162
164
-
pub(crate) fn to_column_range(&self) -> Range<usize> {
163
+
pub(crate) fn to_column_range(&self) -> std::ops::Range<usize> {
165
164
self.column..self.column + 1
166
165
}
167
166
}
···
173
172
}
174
173
175
174
// ----------------------------------------------------------------------------
175
+
// Range
176
+
177
+
/// The range of a graph DSL entity within its file
178
+
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
179
+
pub struct Range {
180
+
pub start: Location,
181
+
pub end: Location,
182
+
}
183
+
184
+
impl Display for Range {
185
+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
186
+
write!(f, "{} - {}", self.start, self.end)
187
+
}
188
+
}
189
+
190
+
// ----------------------------------------------------------------------------
176
191
// Parser
177
192
178
193
struct Parser<'a> {
···
350
365
}
351
366
352
367
fn parse_stanza(&mut self, language: Language) -> Result<ast::Stanza, ParseError> {
353
-
let location = self.location;
368
+
let start = self.location;
354
369
let (query, full_match_stanza_capture_index) = self.parse_query(language)?;
355
370
self.consume_whitespace();
356
371
let statements = self.parse_statements()?;
372
+
let end = self.location;
373
+
let range = Range { start, end };
357
374
Ok(ast::Stanza {
358
375
query,
359
376
statements,
360
377
full_match_stanza_capture_index,
361
378
full_match_file_capture_index: usize::MAX, // set in checker
362
-
location,
379
+
range,
363
380
})
364
381
}
365
382