MCPcopy Create free account
hub / github.com/amber-lang/amber / parse

Method parse

src/modules/function/declaration.rs:240–375  ·  view source on GitHub ↗
(&mut self, meta: &mut ParserMetadata)

Source from the content-addressed store, hash-verified

238 }
239
240 fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult {
241 // Parse the function comment
242 if is_functions_comment_doc(meta) {
243 let mut comment = CommentDoc::new();
244 syntax(meta, &mut comment)?;
245 self.comment = Some(comment);
246 }
247 // Get all the user-defined compiler flags
248 while let Ok(flag) = token_by(meta, |val| val.starts_with("#[")) {
249 // Push to the flags vector as it is more safe in case of parsing errors
250 self.flags
251 .insert(get_ccflag_by_name(&flag[2..flag.len() - 1]));
252 }
253 let doc_index = meta.get_index();
254 // Check if this function is public
255 if token(meta, "pub").is_ok() {
256 self.is_public = true;
257 }
258 token(meta, "fun")?;
259 // Get the function name
260 self.name_token = meta.get_current_token();
261 self.name = variable(meta, variable_name_extensions())?;
262 let mut optional = false;
263 context!(
264 {
265 // Get the arguments
266 token(meta, "(")?;
267 loop {
268 // Skip comments and newlines
269 if token_by(meta, |token| {
270 token.starts_with("//") || token.starts_with('\n')
271 })
272 .is_ok()
273 {
274 continue;
275 }
276 if token(meta, ")").is_ok() {
277 break;
278 }
279 let is_ref = token(meta, "ref").is_ok();
280 let name_token = meta.get_current_token();
281 let name = variable(meta, variable_name_extensions())?;
282
283 // Optionally parse the argument type
284 let arg_type = match token(meta, ":") {
285 Ok(_) => parse_type(meta)?,
286 Err(_) => Type::Generic,
287 };
288
289 // Optionally parse default value
290 let optional_expr = match token(meta, "=") {
291 Ok(_) => {
292 optional = true;
293 let mut expr = Expr::new();
294 syntax(meta, &mut expr)?;
295 Some(expr)
296 }
297 Err(_) => None,

Callers

nothing calls this directly

Calls 4

is_functions_comment_docFunction · 0.85
get_ccflag_by_nameFunction · 0.85
variable_name_extensionsFunction · 0.85
get_indexMethod · 0.80

Tested by

no test coverage detected