Skip to content

Parser fails in the presence of brace in comment #19

Open
@braised-babbage

Description

@braised-babbage

The following OpenPulse program fails to parse

cal {
  // while(true) {
  int x;
}

The error I see is

In [10]: parse("""cal {
    ...: // while(true) {
    ...: int x;
    ...: }
    ...: """)
---------------------------------------------------------------------------
ParseCancellationException                Traceback (most recent call last)
File ~/source/interpres/.venv/lib/python3.10/site-packages/openqasm3/parser.py:87, in parse(input_, permissive)
     86 try:
---> 87     tree = parser.program()
     88 except (RecognitionException, ParseCancellationException) as exc:

File ~/source/interpres/.venv/lib/python3.10/site-packages/openqasm3/_antlr/_4_11/qasm3Parser.py:640, in qasm3Parser.program(self)
    639 self.state = 131
--> 640 self.statement()
    641 self.state = 136

File ~/source/interpres/.venv/lib/python3.10/site-packages/openqasm3/_antlr/_4_11/qasm3Parser.py:919, in qasm3Parser.statement(self)
    918 self.state = 155
--> 919 self.calStatement()
    920 pass

File ~/source/interpres/.venv/lib/python3.10/site-packages/openqasm3/_antlr/_4_11/qasm3Parser.py:3352, in qasm3Parser.calStatement(self)
   3351     self.state = 423
-> 3352     self.match(qasm3Parser.RBRACE)
   3353 except RecognitionException as re:

File ~/source/interpres/.venv/lib/python3.10/site-packages/antlr4/Parser.py:126, in Parser.match(self, ttype)
    125 else:
--> 126     t = self._errHandler.recoverInline(self)
    127     if self.buildParseTrees and t.tokenIndex==-1:
    128         # we must have conjured up a new token during single token insertion
    129         # if it's not the current symbol

File ~/source/interpres/.venv/lib/python3.10/site-packages/antlr4/error/ErrorStrategy.py:703, in BailErrorStrategy.recoverInline(self, recognizer)
    702 def recoverInline(self, recognizer:Parser):
--> 703     self.recover(recognizer, InputMismatchException(recognizer))

File ~/source/interpres/.venv/lib/python3.10/site-packages/antlr4/error/ErrorStrategy.py:697, in BailErrorStrategy.recover(self, recognizer, e)
    696     context = context.parentCtx
--> 697 raise ParseCancellationException(e)

ParseCancellationException: None

Note that the OpenQASM parser doesn't have a problem with the following

while (true) {
  // while(true) {
  int x;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions