Skip to content

Commit

Permalink
fix: add fallback to try parsing pragma name as commend
Browse files Browse the repository at this point in the history
  • Loading branch information
jselig-rigetti committed Oct 24, 2023
1 parent d303519 commit 6d54402
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions quil-rs/src/parser/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,13 @@ pub(crate) fn parse_store<'a>(input: ParserInput<'a>) -> InternalParserResult<'a

/// Parse the contents of a `PRAGMA` instruction.
pub(crate) fn parse_pragma<'a>(input: ParserInput<'a>) -> InternalParserResult<'a, Instruction> {
let (input, pragma_type) = token!(Identifier(v))(input)?;
let (input, pragma_type) = token!(Identifier(v))(input).or_else(|err| {
// If the pragma's type is the name of a command (e.g. "DELAY"),
// it will be lexed as a command token instead of an identifier.
token!(Command(v))(input)
.map(|(input, command)| (input, command.to_string()))
.map_err(|_| err)
})?;
let (input, arguments) = many0(alt((
map(token!(Identifier(v)), PragmaArgument::Identifier),
map(token!(Integer(i)), PragmaArgument::Integer),
Expand Down Expand Up @@ -787,9 +793,7 @@ mod tests {
"DELAY 0 \"0.1\"",
Instruction::Pragma(Pragma {
name: "DELAY".to_string(),
arguments: vec![
PragmaArgument::Integer(0)
],
arguments: vec![PragmaArgument::Integer(0)],
data: Some("0.1".to_string()),
})
);
Expand Down

0 comments on commit 6d54402

Please sign in to comment.