MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / scan_word

Method scan_word

cranelift/reader/src/lexer.rs:315–341  ·  view source on GitHub ↗

Scan a 'word', which is an identifier-like sequence of characters beginning with '_' or an alphabetic char, followed by zero or more alphanumeric or '_' characters.

(&mut self)

Source from the content-addressed store, hash-verified

313 // Scan a 'word', which is an identifier-like sequence of characters beginning with '_' or an
314 // alphabetic char, followed by zero or more alphanumeric or '_' characters.
315 fn scan_word(&mut self) -> Result<LocatedToken<'a>, LocatedError> {
316 let begin = self.pos;
317 let loc = self.loc();
318
319 assert!(self.lookahead == Some('_') || self.lookahead.unwrap().is_ascii_alphabetic());
320 loop {
321 match self.next_ch() {
322 Some('_') | Some('0'..='9') | Some('a'..='z') | Some('A'..='Z') => {}
323 _ => break,
324 }
325 }
326 let text = &self.source[begin..self.pos];
327
328 // Look for numbered well-known entities like block15, v45, ...
329 token(
330 split_entity_name(text)
331 .and_then(|(prefix, number)| {
332 Self::numbered_entity(prefix, number)
333 .or_else(|| Self::value_type(text, prefix, number))
334 })
335 .unwrap_or_else(|| match text {
336 "cold" => Token::Cold,
337 _ => Token::Identifier(text),
338 }),
339 loc,
340 )
341 }
342
343 // If prefix is a well-known entity prefix and suffix is a valid entity number, return the
344 // decoded token.

Callers 1

nextMethod · 0.80

Calls 5

tokenFunction · 0.85
split_entity_nameFunction · 0.85
value_typeFunction · 0.85
locMethod · 0.80
next_chMethod · 0.80

Tested by

no test coverage detected