Skip to main content

keyword_name_token_spans

Function keyword_name_token_spans 

pub fn keyword_name_token_spans(source: &str) -> Vec<(Span, bool)>
Expand description

#2837: the span of every reserved word written as a name, with whether it names a method (called, or declared with fn T.name() rather than a field. A keyword admitted as a label ({ type: String }) or as a member on the .’s line (a.type, Sorted.from(xs)) is lexed as a keyword, so a client that colours by spelling shows it as one; a property or method token says what it is. The index already tokens a field’s declaration and uses; the caller keeps the index’s token where both have one.

Wider than the parser: it does not know the file parses, so it also tokens a keyword in broken code that the parser would refuse (a foo. then a keyword on the same line, say). Harmless for a colour, wrong for nothing else.

Lexical, so it needs no parse: the two admitting contexts are the same token shapes the parser tests. A keyword label opens an entry ({, , or ( before it) and a member shares a line with its ..