Skip to content

Commit

Permalink
fix(parser): reset stream position for direct string input, close #35 (
Browse files Browse the repository at this point in the history
…#39)

Hi Team,

The root cause of #35 is as
follows


https://github.com/openqasm/qe-qasm/blob/main/lib/Parser/QasmParser.y#L338-L342

Here `IIS` and `ISS` points to the same buffer, as `std::getline` moves
the pointer to the next line, we got the wrong line number when directly
parsing string.

Thus we just need to reset the position of `IIS` to make
`QASM::QasmPreprocessor::Instance().Preprocess(IIS)` work as expected


I did not find any test codes in this repo to directly test
`QasmParser.y`. I'm willing to add some tests and wish to know the
proper way to do so.

Thanks,
Yilun
  • Loading branch information
Zhaoyilunnn authored Jul 29, 2024
1 parent ec7731b commit 654ea08
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Parser/QasmParser.y
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ int yyparse() {
if (OQ != "OPENQASM" || OV.empty())
QASM::ASTOpenQASMVersionTracker::Instance().SetVersion(3.0);

if (IIS) {
IIS->clear();
IIS->seekg(0, std::ios::beg);
}

if (!QASM::QasmPreprocessor::Instance().Preprocess(IIS)) {
std::stringstream M;
M << "OpenQASM Preprocessor failure!";
Expand Down

0 comments on commit 654ea08

Please sign in to comment.