Struct ExprSpan
pub struct ExprSpan {
pub start: Span,
pub end: Span,
}Expand description
Source range of an AST node: start of its first token to end of its last.
Two proc_macro2::Spans (not a [crate::SourceSpan]) so the future macro-compilation backend
can attach compile_error!/quote_spanned!, and so the (separate, deferred) comment/trivia
pass can call Span::source_text(). crate::SourceSpan remains the Send + Sync wire format
used only at the CELError diagnostic boundary; this AST is an internal parser artifact using
the same span currency the parser itself already does.
proc_macro2::Span isn’t PartialEq, so neither is this type — shape tests should match
structurally and ignore spans rather than assert exact span equality.
Fields§
§start: SpanStart of the first token of the node.
end: SpanEnd of the last token of the node.
Implementations§
§impl ExprSpan
impl ExprSpan
pub fn for_text(text: &str) -> ExprSpan
pub fn for_text(text: &str) -> ExprSpan
Creates a span whose source_text() returns exactly text, by
tokenizing it and taking the resulting token’s span. For hand-built
AST nodes (not produced by parsing real source), this gives leaves
like a type name or literal a span the formatter can read back
text from, the same way cel-rs-macros already does internally.
-
Precondition:
texttokenizes to exactly one token tree. -
Complexity: O(n) in
text.len()(it lexestext).
§Examples
use cel_parser::ExprSpan;
let span = ExprSpan::for_text("i64");
assert_eq!(span.start.source_text().as_deref(), Some("i64"));