MCPcopy Create free account
hub / github.com/PerroEngine/Perro / resolve_path

Function resolve_path

perro_source/render_stack/perro_macros/src/lib.rs:107–142  ·  view source on GitHub ↗
(path: &str)

Source from the content-addressed store, hash-verified

105 if group.delimiter() != Delimiter::Parenthesis {
106 return Err("concat! must use parentheses".to_string());
107 }
108 let mut paths = Vec::new();
109 let mut item = TokenStream::new();
110 for token in group.stream() {
111 if matches!(&token, TokenTree::Punct(p) if p.as_char() == ',') {
112 if item.is_empty() {
113 return Err("concat! contains empty item".to_string());
114 }
115 paths.extend(parse_input(item)?);
116 item = TokenStream::new();
117 } else {
118 item.extend([token]);
119 }
120 }
121 if !item.is_empty() {
122 paths.extend(parse_input(item)?);
123 }
124 if paths.is_empty() {
125 return Err("concat! needs at least one source".to_string());
126 }
127 Ok(paths)
128}
129
130fn parse_include_str(group: &Group) -> Result<String, String> {
131 if group.delimiter() != Delimiter::Parenthesis {
132 return Err("include_str! must use parentheses".to_string());
133 }
134 let inner: Vec<TokenTree> = group.stream().into_iter().collect();
135 match inner.as_slice() {
136 [TokenTree::Literal(lit)] => parse_string_literal(&lit.to_string()),
137 _ => Err("include_str! must contain exactly one string literal".to_string()),
138 }
139}
140
141fn parse_string_literal(raw: &str) -> Result<String, String> {
142 if raw.len() < 2 || !raw.starts_with('"') || !raw.ends_with('"') {
143 return Err("expected string literal".to_string());
144 }
145 let s = &raw[1..raw.len() - 1];

Callers 3

emit_minifiedFunction · 0.70
on_initMethod · 0.50

Calls 4

collect_suffix_matchesFunction · 0.85
joinMethod · 0.80
lenMethod · 0.45
removeMethod · 0.45

Tested by 2

on_initMethod · 0.40