Skip to content

Commit 3965c96

Browse files
authored
🐛 pretty printing of Reset and parsing of cx (#5)
* fix missing ; for Reset * Add cx alias for CX --------- Co-authored-by: liam <lgh@e.email>
1 parent 68f4599 commit 3965c96

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/parse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ RBNF.@parser QASMLang begin
5353
uop = (inst | ugate | csemantic_gate)
5454
inst::Instruction := [name = id, ['(', [cargs = explist].?, ')'].?, qargs = bitlist, ';']
5555
ugate::UGate := [:U, '(', z1 = exp, ',', y = exp, ',', z2 = exp, ')', qarg = bit, ';']
56-
csemantic_gate::CXGate := [:CX, ctrl = bit, ',', qarg = bit, ';']
56+
csemantic_gate::CXGate := [:CX | :cx, ctrl = bit, ',', qarg = bit, ';']
5757

5858
idlist = @direct_recur begin
5959
init = [id]

src/types.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ end
271271
function print_qasm(io::IO, stmt::Reset)
272272
print_kw(io, "reset ")
273273
print_qasm(io, stmt.qarg)
274+
print(io, ";")
274275
end
275276

276277
function print_qasm(io::IO, stmt::Measure)

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ end
5959
measure q[0] -> c0[0];
6060
if(c0==1) z q[2];
6161
u3(0.1 + 0.2, 0.2, 0.3) q[0];
62+
reset q[0];
6263
"""
6364

6465
ast = OpenQASM.parse(qasm)
@@ -266,6 +267,14 @@ end
266267
@test inst.cargs[3].str == "0.3"
267268
end
268269

270+
@testset "reset" begin
271+
reset = ast.prog[15]
272+
@test reset isa Reset
273+
@test reset.qarg.name.str == "q"
274+
@test reset.qarg.address.str == "0"
275+
@test string(reset) == "reset q[0];"
276+
end
277+
269278
end
270279

271280
@testset "cmp_ast" begin

0 commit comments

Comments
 (0)