MCPcopy Index your code
hub / github.com/carllerche/assert-struct / parse

Method parse

assert-struct-macros/src/pattern/set.rs:31–81  ·  view source on GitHub ↗

Parses a set pattern: #(pattern, pattern, ..) # Example Input ```text #(1, 2, 3) #(> 0, < 10, ..) #(_ { kind: "click", .. }, ..) ```

(input: syn::parse::ParseStream)

Source from the content-addressed store, hash-verified

29 /// #(_ { kind: "click", .. }, ..)
30 /// ```
31 fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
32 // Capture the span of the `#` token before consuming anything
33 let hash_span = input.span();
34
35 // Consume the # token
36 let _: Token![#] = input.parse()?;
37
38 let content;
39 let paren = syn::parenthesized!(content in input);
40
41 // Full span from `#` to closing `)`
42 let span = hash_span.join(paren.span.close()).unwrap_or(hash_span);
43
44 let mut elements = Vec::new();
45 let mut rest = false;
46
47 while !content.is_empty() {
48 // Check for rest pattern (..)
49 if content.peek(Token![..]) {
50 let _: Token![..] = content.parse()?;
51 rest = true;
52 // Optional trailing comma
53 if content.peek(Token![,]) {
54 let _: Token![,] = content.parse()?;
55 }
56 break;
57 }
58
59 elements.push(content.parse()?);
60
61 if content.is_empty() {
62 break;
63 }
64
65 let _: Token![,] = content.parse()?;
66
67 // Rest pattern can appear after a comma
68 if content.peek(Token![..]) {
69 let _: Token![..] = content.parse()?;
70 rest = true;
71 break;
72 }
73 }
74
75 Ok(PatternSet {
76 node_id: next_node_id(),
77 span,
78 elements,
79 rest,
80 })
81 }
82}

Callers

nothing calls this directly

Calls 4

next_node_idFunction · 0.85
is_emptyMethod · 0.80
pushMethod · 0.80
spanMethod · 0.45

Tested by

no test coverage detected