MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_run_command

Function parse_run_command

cranelift/reader/src/parser.rs:183–195  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

181/// - `Ok(Some(command))` if the comment is intended as a `RunCommand` and can be parsed to one
182/// - `Err` otherwise.
183pub 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
197pub struct Parser<'a> {
198 lex: Lexer<'a>,

Callers 5

run_testFunction · 0.85
run_testFunction · 0.85
run_a_commandFunction · 0.85
runMethod · 0.85
run_file_contentsFunction · 0.85

Calls 5

OkFunction · 0.85
tokenMethod · 0.80
parse_run_commandMethod · 0.80
newFunction · 0.50
mapMethod · 0.45

Tested by 3

run_testFunction · 0.68
run_testFunction · 0.68
run_a_commandFunction · 0.68