Skip to content
This repository was archived by the owner on Sep 13, 2019. It is now read-only.

Conversation

danbev
Copy link
Contributor

@danbev danbev commented Jun 20, 2019

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' } } ]

This commit adds support for comments in grammar.js.

The motivation of this is somewhat of a long shot. When using the IBM
Quantum Experience and the QASM editor, if one adds commments 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' } } ]
@danbev danbev changed the title support comments in grammar.js support comments in grammar.jison Jun 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant