Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle final comments with no terminating newline in OpenQASM 2 #10773

Merged
merged 3 commits into from
Sep 5, 2023

Conversation

jakelishman
Copy link
Member

Summary

Previously, if an OpenQASM 2 program to be parsed ended in a comment with no terminating '\n', the lexer would fail to notice the end of the file and would instead attempt to emit the second '/' of the comment introduction as a 'Slash` token.

Details and comments

Fix #10770.

Previously, if an OpenQASM 2 program to be parsed ended in a comment
with no terminating '\n', the lexer would fail to notice the end of the
file and would instead attempt to emit the second '/' of the comment
introduction as a 'Slash` token.
@jakelishman jakelishman added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qasm2 Relating to OpenQASM 2 import or export Rust This PR or issue is related to Rust code in the repository labels Sep 5, 2023
@jakelishman jakelishman added this to the 0.25.2 milestone Sep 5, 2023
@jakelishman jakelishman requested a review from a team as a code owner September 5, 2023 14:50
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

Eric-Arellano
Eric-Arellano previously approved these changes Sep 5, 2023
Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

mtreinish
mtreinish previously approved these changes Sep 5, 2023
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM it seems fairly straightforward. Just one question inline about a potential extra test case. If you don't think it's worth it feel free to just add it to the merge queue.

def test_allows_empty(self):
self.assertEqual(qiskit.qasm2.loads(""), QuantumCircuit())

@ddt.data("", "\n", "\r\n", "\n ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to test "\n\t" and "\r\n\t" too? Just thinking of other whitespace combinations to make the testing here a bit more thorough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra cases added in c410d75

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only one of these cases that was actually buggy was the one with no whitespace at all, but it doesn't matter a great deal that there's additional cases.

Copy link
Member

@1ucian0 1ucian0 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed you were already afk, so I took the liberty of adding them. I hope you dont mind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok, it's all our code anyway.

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@1ucian0 1ucian0 dismissed stale reviews from mtreinish and Eric-Arellano via c410d75 September 5, 2023 19:01
@1ucian0 1ucian0 added this pull request to the merge queue Sep 5, 2023
Merged via the queue into Qiskit:main with commit 3075f14 Sep 5, 2023
14 checks passed
mergify bot pushed a commit that referenced this pull request Sep 5, 2023
* Handle final comments with no terminating newline in OpenQASM 2

Previously, if an OpenQASM 2 program to be parsed ended in a comment
with no terminating '\n', the lexer would fail to notice the end of the
file and would instead attempt to emit the second '/' of the comment
introduction as a 'Slash` token.

* Run `cargo fmt`

* Testing extra cases

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

---------

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit 3075f14)
@jakelishman jakelishman deleted the qasm2/final-comments branch September 6, 2023 08:07
github-merge-queue bot pushed a commit that referenced this pull request Sep 6, 2023
…) (#10778)

* Handle final comments with no terminating newline in OpenQASM 2

Previously, if an OpenQASM 2 program to be parsed ended in a comment
with no terminating '\n', the lexer would fail to notice the end of the
file and would instead attempt to emit the second '/' of the comment
introduction as a 'Slash` token.

* Run `cargo fmt`

* Testing extra cases

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

---------

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit 3075f14)

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qasm2 Relating to OpenQASM 2 import or export Rust This PR or issue is related to Rust code in the repository stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comments at the end of an OpenQasm 2.0 circuits gives an error
5 participants