Skip to main content

ptx_parser/
span.rs

1use crate::parser::Span;
2
3/// Trait implemented by AST nodes that carry a source span.
4pub trait Spanned: Sized {
5    /// Returns the stored span for this node.
6    fn span(&self) -> Span;
7
8    /// Mutates the stored span in-place.
9    fn set_span(&mut self, span: Span);
10
11    /// Convenience helper that sets the span and returns `self`.
12    fn with_span(mut self, span: Span) -> Self {
13        self.set_span(span);
14        self
15    }
16}
17
18#[macro_export]
19macro_rules! span {
20    ($range:expr) => {{
21        let r = $range;
22        $crate::Span::new(r.start, r.end)
23    }};
24}