libgraphql_parser/graphql_source_span.rs
1use crate::SourcePosition;
2use std::path::PathBuf;
3
4/// Represents a span of source text from start to end position.
5///
6/// The span is a half-open interval: `[start_inclusive, end_exclusive)`.
7/// - `start_inclusive`: Position of the first character of the source text
8/// - `end_exclusive`: Position immediately after the last character
9///
10/// Optionally includes a file path for the referenced source text.
11#[derive(Clone, Debug, Eq, PartialEq)]
12pub struct GraphQLSourceSpan {
13 pub start_inclusive: SourcePosition,
14 pub end_exclusive: SourcePosition,
15 /// The file path to the source text this span refers to, if available.
16 pub file_path: Option<PathBuf>,
17}
18
19impl GraphQLSourceSpan {
20 /// Creates a span without file path information.
21 pub fn new(start: SourcePosition, end: SourcePosition) -> Self {
22 Self {
23 start_inclusive: start,
24 end_exclusive: end,
25 file_path: None,
26 }
27 }
28
29 /// Creates a span with file path information.
30 pub fn with_file(start: SourcePosition, end: SourcePosition, file_path: PathBuf) -> Self {
31 Self {
32 start_inclusive: start,
33 end_exclusive: end,
34 file_path: Some(file_path),
35 }
36 }
37}