Parse a CLIF run command. run-command ::= "run" [":" invocation comparison expected] \ "print" [":" invocation]
(&mut self, sig: &Signature)
| 2502 | /// run-command ::= "run" [":" invocation comparison expected] |
| 2503 | /// \ "print" [":" invocation] |
| 2504 | fn parse_run_command(&mut self, sig: &Signature) -> ParseResult<RunCommand> { |
| 2505 | // skip semicolon |
| 2506 | match self.token() { |
| 2507 | Some(Token::Identifier("run")) => { |
| 2508 | self.consume(); |
| 2509 | if self.optional(Token::Colon) { |
| 2510 | let invocation = self.parse_run_invocation(sig)?; |
| 2511 | let comparison = self.parse_run_comparison()?; |
| 2512 | let expected = self.parse_run_returns(sig)?; |
| 2513 | Ok(RunCommand::Run(invocation, comparison, expected)) |
| 2514 | } else if sig.params.is_empty() |
| 2515 | && sig.returns.len() == 1 |
| 2516 | && sig.returns[0].value_type.is_int() |
| 2517 | { |
| 2518 | // To match the existing run behavior that does not require an explicit |
| 2519 | // invocation, we create an invocation from a function like `() -> i*` and |
| 2520 | // require the result to be non-zero. |
| 2521 | let invocation = Invocation::new("default", vec![]); |
| 2522 | let expected = vec![DataValue::I8(0)]; |
| 2523 | let comparison = Comparison::NotEquals; |
| 2524 | Ok(RunCommand::Run(invocation, comparison, expected)) |
| 2525 | } else { |
| 2526 | Err(self.error("unable to parse the run command")) |
| 2527 | } |
| 2528 | } |
| 2529 | Some(Token::Identifier("print")) => { |
| 2530 | self.consume(); |
| 2531 | if self.optional(Token::Colon) { |
| 2532 | Ok(RunCommand::Print(self.parse_run_invocation(sig)?)) |
| 2533 | } else if sig.params.is_empty() { |
| 2534 | // To allow printing of functions like `() -> *`, we create a no-arg invocation. |
| 2535 | let invocation = Invocation::new("default", vec![]); |
| 2536 | Ok(RunCommand::Print(invocation)) |
| 2537 | } else { |
| 2538 | Err(self.error("unable to parse the print command")) |
| 2539 | } |
| 2540 | } |
| 2541 | _ => Err(self.error("expected a 'run:' or 'print:' command")), |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | /// Parse the invocation of a CLIF function. |
| 2546 | /// |
no test coverage detected