Reads the module spec at token `j`: a quoted string or a dotted bare name. Returns (spec, index past it). */
(src: &str, tokens: &[Token], j: usize)
| 161 | |
| 162 | /* Reads the module spec at token `j`: a quoted string or a dotted bare name. Returns (spec, index past it). */ |
| 163 | fn read_spec(src: &str, tokens: &[Token], j: usize) -> Option<(ImportSpec, usize)> { |
| 164 | let t = tokens.get(j)?; |
| 165 | match t.kind { |
| 166 | TokenType::String => Some((ImportSpec::Quoted(unquote(&src[t.start..t.end])), j + 1)), |
| 167 | TokenType::Name => { |
| 168 | let mut name = src[t.start..t.end].to_string(); |
| 169 | let mut k = j + 1; |
| 170 | // Dotted segments: a.b.c. |
| 171 | while tokens.get(k).map(|x| x.kind) == Some(TokenType::Dot) { |
| 172 | let Some(seg) = tokens.get(k + 1).filter(|s| s.kind == TokenType::Name) else { break }; |
| 173 | name.push('.'); |
| 174 | name.push_str(&src[seg.start..seg.end]); |
| 175 | k += 2; |
| 176 | } |
| 177 | Some((ImportSpec::Bare(name), k)) |
| 178 | } |
| 179 | _ => None, |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /* Every import spec, classified Bare vs Quoted, via the lexer so a `from`/`import` inside a comment or string is never a false hit. */ |
| 184 | pub fn scan_imports(src: &str) -> Vec<ImportSpec> { |
no test coverage detected