Skip to content

Commit

Permalink
New: support gate modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
notmgsk committed Jul 22, 2021
1 parent 00a69f3 commit 9810cb5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/parser/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,24 @@ pub fn parse_gate<'a>(input: ParserInput<'a>) -> ParserResult<'a, Instruction> {
},
))
}

#[cfg(test)]
mod test {
use super::parse_gate;
use crate::expression::Expression;
use crate::instruction::{GateModifier, Instruction, Qubit};
use crate::make_test;
use crate::parser::lexer::lex;

make_test!(
test_modifiers,
parse_gate,
"DAGGER CONTROLLED RX(pi) 0 1",
Instruction::Gate {
name: "RX".to_string(),
parameters: vec![Expression::PiConstant],
qubits: vec![Qubit::Fixed(0), Qubit::Fixed(1)],
modifiers: vec![GateModifier::Dagger, GateModifier::Controlled],
}
);
}
2 changes: 1 addition & 1 deletion src/parser/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn parse_instruction(input: ParserInput) -> ParserResult<Instruction> {
})
}
Some((Token::NonBlocking, _)) => command::parse_pulse(input),
Some((Token::Identifier(_), _)) => gate::parse_gate(input),
Some((Token::Identifier(_), _)) | Some((Token::Modifier(_), _)) => gate::parse_gate(input),
Some((_, _)) => Err(nom::Err::Failure(Error {
input: &input[..1],
error: ErrorKind::NotACommandOrGate,
Expand Down

0 comments on commit 9810cb5

Please sign in to comment.