qiskit-js
qiskit-js copied to clipboard
support comments in grammar.jison
Summary
support comments in grammar.jison
Details and comments
This commit adds support for comments in grammar.jison.
The motivation of this is somewhat of a long shot. When using the IBM Quantum Experience and the QASM editor, if one adds comments to the code then these are removed upon saving. It would be nice if these were saved and is why this commit came about. I don't know anything about how or if this is actually used for the Quantum Experience but thought it would be worth a try. There is probably more cleaning up to be done and additional test to be added but I wanted to get some feedback on this before proceeding.
Example with comments:
$ cat example.qasm
// First Quantum Circuit
IBMQASM 2.0;
include "qelib1.inc";
// quantum registers
qreg q[1];
// classic registers
creg c[1];
x q[1];
measure q -> c;
Output:
[ { type: 'comment', value: '// First Quantum Circuit', line: 0 },
{ type: 'comment', value: '// quantum registers', line: 3 },
{ type: 'qubit', identifier: 'q', number: '1' },
{ type: 'comment', value: '// classic registers', line: 5 },
{ type: 'clbit', identifier: 'c', number: '1' },
{ type: 'gate',
name: 'x',
identifiers: [ { name: 'q', index: '1' } ] },
{ type: 'measure', qreg: { name: 'q' }, creg: { name: 'c' } } ]