Parse a CLIF comment `text` as a run command. Return: - `Ok(None)` if the comment is not intended to be a `RunCommand` (i.e. does not start with `run` or `print` - `Ok(Some(command))` if the comment is intended as a `RunCommand` and can be parsed to one - `Err` otherwise.
(text: &str, signature: &Signature)
| 181 | /// - `Ok(Some(command))` if the comment is intended as a `RunCommand` and can be parsed to one |
| 182 | /// - `Err` otherwise. |
| 183 | pub fn parse_run_command(text: &str, signature: &Signature) -> ParseResult<Option<RunCommand>> { |
| 184 | let _tt = timing::parse_text(); |
| 185 | // We remove leading spaces and semi-colons for convenience here instead of at the call sites |
| 186 | // since this function will be attempting to parse a RunCommand from a CLIF comment. |
| 187 | let trimmed_text = text.trim_start_matches(|c| c == ' ' || c == ';'); |
| 188 | let mut parser = Parser::new(trimmed_text); |
| 189 | match parser.token() { |
| 190 | Some(Token::Identifier("run")) | Some(Token::Identifier("print")) => { |
| 191 | parser.parse_run_command(signature).map(|c| Some(c)) |
| 192 | } |
| 193 | Some(_) | None => Ok(None), |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | pub struct Parser<'a> { |
| 198 | lex: Lexer<'a>, |