File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,7 +87,14 @@ def parse_openpulse(
8787 try :
8888 tree = parser .calibrationBlock ()
8989 except (RecognitionException , ParseCancellationException ) as exc :
90- raise OpenPulseParsingError () from exc
90+ msg = ''
91+ # With BailErrorStrategy, we should be able to recover and report
92+ # information about the offending token.
93+ if isinstance (exc , ParseCancellationException ) and exc .args :
94+ tok = getattr (exc .args [0 ], 'offendingToken' , None )
95+ if tok is not None :
96+ msg = f"Unexpected token '{ tok .text } ' at line { tok .line } , column { tok .start } ."
97+ raise OpenPulseParsingError (msg ) from exc
9198 result = (
9299 OpenPulseNodeVisitor (in_defcal ).visitCalibrationBlock (tree )
93100 if tree .children
Original file line number Diff line number Diff line change @@ -383,7 +383,7 @@ def test_permissive_parsing(capsys):
383383 captured = capsys .readouterr ()
384384 assert captured .err .strip () == "line 2:9 no viable alternative at input 'int;'"
385385
386- with pytest .raises (OpenPulseParsingError ):
386+ with pytest .raises (OpenPulseParsingError , match = r"Unexpected token ';' at line 2, column 10." ):
387387 # This is stricter -- we fail as soon as ANTLR sees a problem
388388 parse (p )
389389 captured = capsys .readouterr ()
You can’t perform that action at this time.
0 commit comments