Parse a script: Script = "script" "{" ( ) ( ) ( ) "}"
(
script_attributes: Vec<Attributes>,
context: &mut Context,
)
| 2360 | // (<Attributes> <SpecBlock>)* |
| 2361 | // "}" |
| 2362 | fn parse_script( |
| 2363 | script_attributes: Vec<Attributes>, |
| 2364 | context: &mut Context, |
| 2365 | ) -> Result<Script, Diagnostic> { |
| 2366 | let start_loc = context.tokens.start_loc(); |
| 2367 | |
| 2368 | consume_token(context.tokens, Tok::Script)?; |
| 2369 | consume_token(context.tokens, Tok::LBrace)?; |
| 2370 | |
| 2371 | let mut uses = vec![]; |
| 2372 | let mut next_item_attributes = parse_attributes(context)?; |
| 2373 | while context.tokens.peek() == Tok::Use { |
| 2374 | uses.push(parse_use_decl(next_item_attributes, context)?); |
| 2375 | next_item_attributes = parse_attributes(context)?; |
| 2376 | } |
| 2377 | let mut constants = vec![]; |
| 2378 | while context.tokens.peek() == Tok::Const { |
| 2379 | let start_loc = context.tokens.start_loc(); |
| 2380 | constants.push(parse_constant_decl( |
| 2381 | next_item_attributes, |
| 2382 | start_loc, |
| 2383 | Modifiers::empty(), |
| 2384 | context, |
| 2385 | )?); |
| 2386 | next_item_attributes = parse_attributes(context)?; |
| 2387 | } |
| 2388 | |
| 2389 | context.tokens.match_doc_comments(); // match doc comments to script function |
| 2390 | let function_start_loc = context.tokens.start_loc(); |
| 2391 | let modifiers = parse_module_member_modifiers(context)?; |
| 2392 | // don't need to check native modifier, it is checked later |
| 2393 | let function = |
| 2394 | parse_function_decl(next_item_attributes, function_start_loc, modifiers, context)?; |
| 2395 | |
| 2396 | let mut specs = vec![]; |
| 2397 | while context.tokens.peek() == Tok::NumSign || context.tokens.peek() == Tok::Spec { |
| 2398 | let attributes = parse_attributes(context)?; |
| 2399 | specs.push(parse_spec_block(attributes, context)?); |
| 2400 | } |
| 2401 | |
| 2402 | if context.tokens.peek() != Tok::RBrace { |
| 2403 | let loc = current_token_loc(context.tokens); |
| 2404 | let msg = "Unexpected characters after end of 'script' function"; |
| 2405 | return Err(diag!(Syntax::UnexpectedToken, (loc, msg))); |
| 2406 | } |
| 2407 | consume_token(context.tokens, Tok::RBrace)?; |
| 2408 | |
| 2409 | let loc = make_loc( |
| 2410 | context.tokens.file_hash(), |
| 2411 | start_loc, |
| 2412 | context.tokens.previous_end_loc(), |
| 2413 | ); |
| 2414 | Ok(Script { |
| 2415 | attributes: script_attributes, |
| 2416 | loc, |
| 2417 | uses, |
| 2418 | constants, |
| 2419 | function, |
no test coverage detected