Enhance QASM parser to support multi-character register names #279
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this patch, the QASM parser could only parse
creg
orqreg
declarations with a length of 1 (e.g.,q
orc
). This made it impossible to define or measure quantum registers with variable names longer than one letter.For example, the parser would fail to parse a
qreg
namedq1
.This patch addresses this limitation by enhancing the parser to handle multi-character register names. The key changes are:
The
parse_command
method has been updated to handle themeasure
operation separately. It now correctly extracts the target register name and index, as well as the result register name and index, from themeasure
command.The logic for parsing
qreg
andcreg
declarations has been improved to support multi-character register names. The register name and index are now extracted separately, and the parser checks if the register name is valid before processing the declaration.These changes can be tested by parsing the following QASM code:
The updated parser should now be able to correctly parse the QASM code, including the
qreg
andmeasure
operations with multi-character register names.