MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / read_spec

Function read_spec

compiler/src/modules/packages/mod.rs:163–181  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

161
162/* Reads the module spec at token `j`: a quoted string or a dotted bare name. Returns (spec, index past it). */
163fn 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. */
184pub fn scan_imports(src: &str) -> Vec<ImportSpec> {

Callers 1

scan_importsFunction · 0.85

Calls 3

unquoteFunction · 0.85
pushMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected