rust/proc-macro2/parse.rs
Source file repositories/reference/linux-study-clean/rust/proc-macro2/parse.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/proc-macro2/parse.rs- Extension
.rs- Size
- 28818 bytes
- Lines
- 998
- Domain
- Rust Kernel Layer
- Bucket
- Rust API Membrane
- Inferred role
- Rust Kernel Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function pubfunction block_commentfunction is_whitespacefunction block_commentfunction Errfunction Okfunction Somefunction letfunction leaf_tokenfunction Okfunction Okfunction Somefunction Somefunction Somefunction Somefunction Somefunction Somefunction Errfunction Somefunction Somefunction Errfunction Somefunction Somefunction Somefunction Somefunction Somefunction Okfunction Somefunction Somefunction Somefunction Somefunction word_breakfunction Errfunction Okfunction Somefunction Okfunction Okfunction Okfunction Okfunction Ok
Annotated Snippet
match block_comment(s) {
Ok((rest, _)) => {
s = rest;
continue;
}
Err(Reject) => return s,
}
}
}
match byte {
b' ' | 0x09..=0x0d => {
s = s.advance(1);
continue;
}
b if b.is_ascii() => {}
_ => {
let ch = s.chars().next().unwrap();
if is_whitespace(ch) {
s = s.advance(ch.len_utf8());
continue;
}
}
}
return s;
}
s
}
fn block_comment(input: Cursor) -> PResult<&str> {
if !input.starts_with("/*") {
return Err(Reject);
}
let mut depth = 0usize;
let bytes = input.as_bytes();
let mut i = 0usize;
let upper = bytes.len() - 1;
while i < upper {
if bytes[i] == b'/' && bytes[i + 1] == b'*' {
depth += 1;
i += 1; // eat '*'
} else if bytes[i] == b'*' && bytes[i + 1] == b'/' {
depth -= 1;
if depth == 0 {
return Ok((input.advance(i + 2), &input.rest[..i + 2]));
}
i += 1; // eat '/'
}
i += 1;
}
Err(Reject)
}
fn is_whitespace(ch: char) -> bool {
// Rust treats left-to-right mark and right-to-left mark as whitespace
ch.is_whitespace() || ch == '\u{200e}' || ch == '\u{200f}'
}
fn word_break(input: Cursor) -> Result<Cursor, Reject> {
match input.chars().next() {
Some(ch) if is_ident_continue(ch) => Err(Reject),
Some(_) | None => Ok(input),
}
}
// Rustc's representation of a macro expansion error in expression position or
// type position.
const ERROR: &str = "(/*ERROR*/)";
pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
let mut trees = TokenStreamBuilder::new();
let mut stack = Vec::new();
loop {
input = skip_whitespace(input);
if let Ok((rest, ())) = doc_comment(input, &mut trees) {
input = rest;
continue;
}
#[cfg(span_locations)]
let lo = input.off;
let first = match input.bytes().next() {
Some(first) => first,
None => match stack.last() {
None => return Ok(trees.build()),
Annotation
- Detected declarations: `function pub`, `function block_comment`, `function is_whitespace`, `function block_comment`, `function Err`, `function Ok`, `function Some`, `function let`, `function leaf_token`, `function Ok`.
- Atlas domain: Rust Kernel Layer / Rust API Membrane.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.