pub enum TemplatePart {
Literal {
text: String,
ws: WsPolicy,
span: Span,
},
Capture {
name: Option<CaptureName>,
parser: Box<ParserAst>,
span: Span,
name_span: Option<Span>,
},
}Expand description
One part of a backtick template (§7.9 TemplatePart).
Every part carries its own source span, for the same reason every
ParserAst node does (§7.10, ADR-078): the editor has to colour the
capture name differently from the capture type (§19.11 criterion 4), and
the only alternative to recording the extent where the scanner already knows
it is a second scanner in the language server re-deriving it — the failure
ADR-098 exists to prevent. Spans are interior-relative until
shift_part_spans rebases them onto the file, exactly like the spans on
the parser nodes underneath.
Variants§
Literal
A literal run: the raw matched bytes plus the whitespace policy.
span covers the source the run was decoded from, which is not the
same length as text: \` is two source bytes and one character,
and a policy part decoded from \s+ has an empty text and a two-byte
span.
Capture
A capture {name? : parser}. name is None for anonymous captures.
parser is the capture’s own parser expression, parsed from its own
body (ADR-072), so captures in one template do not share a kind.
span covers the whole capture including both braces; name_span
covers the name as trimmed ({ n :int} names n, not " n "), and
is None exactly when name is. The capture’s type needs no span
here: it is parser.span().
Implementations§
Trait Implementations§
Source§impl Clone for TemplatePart
impl Clone for TemplatePart
Source§fn clone(&self) -> TemplatePart
fn clone(&self) -> TemplatePart
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more