File tree 2 files changed +9
-2
lines changed
2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,14 @@ def parse_openpulse(
87
87
try :
88
88
tree = parser .calibrationBlock ()
89
89
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
91
98
result = (
92
99
OpenPulseNodeVisitor (in_defcal ).visitCalibrationBlock (tree )
93
100
if tree .children
Original file line number Diff line number Diff line change @@ -383,7 +383,7 @@ def test_permissive_parsing(capsys):
383
383
captured = capsys .readouterr ()
384
384
assert captured .err .strip () == "line 2:9 no viable alternative at input 'int;'"
385
385
386
- with pytest .raises (OpenPulseParsingError ):
386
+ with pytest .raises (OpenPulseParsingError , match = r"Unexpected token ';' at line 2, column 10." ):
387
387
# This is stricter -- we fail as soon as ANTLR sees a problem
388
388
parse (p )
389
389
captured = capsys .readouterr ()
You can’t perform that action at this time.
0 commit comments