Skip to content

Commit d530217

Browse files
committed
SyntaxError in python 10+ has two new attributes end_offset and end_lineNo
1 parent d865565 commit d530217

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

Source/PythonEngine.pas

+35-14
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,8 @@ EPySyntaxError = class (EPyStandardError)
10601060
ELineStr: UnicodeString;
10611061
ELineNumber: Integer;
10621062
EOffset: Integer;
1063+
EEndLineNumber: Integer;
1064+
EEndOffset: Integer;
10631065
end;
10641066
EPyIndentationError = class (EPySyntaxError);
10651067
EPyTabError = class (EPyIndentationError);
@@ -5004,12 +5006,14 @@ procedure TPythonEngine.RaiseError;
50045006

50055007
function DefineSyntaxError( E : EPySyntaxError; const sType, sValue : UnicodeString; err_type, err_value : PPyObject ) : EPySyntaxError;
50065008
var
5007-
s_value : UnicodeString;
5008-
s_line : UnicodeString;
5009-
s_filename : UnicodeString;
5010-
i_line_number : Integer;
5011-
i_offset : Integer;
5012-
tmp : PPyObject;
5009+
s_value : UnicodeString;
5010+
s_line : UnicodeString;
5011+
s_filename : UnicodeString;
5012+
i_line_number : Integer;
5013+
i_offset : Integer;
5014+
i_end_line_number : Integer;
5015+
i_end_offset : Integer;
5016+
tmp : PPyObject;
50135017
begin
50145018
Result := E;
50155019
Result.EName := sType;
@@ -5019,8 +5023,10 @@ procedure TPythonEngine.RaiseError;
50195023
s_filename := '';
50205024
i_line_number := 0;
50215025
i_offset := 0;
5026+
i_end_line_number := 0;
5027+
i_end_offset := 0;
50225028
// Sometimes there's a tuple instead of instance...
5023-
if PyTuple_Check( err_value ) and (PyTuple_Size( err_value) >= 2) then
5029+
if PyTuple_Check(err_value) and (PyTuple_Size( err_value) >= 2) then
50245030
begin
50255031
s_value := PyObjectAsString(PyTuple_GetItem( err_value, 0));
50265032
err_value := PyTuple_GetItem( err_value, 1);
@@ -5065,19 +5071,34 @@ procedure TPythonEngine.RaiseError;
50655071
if Assigned(tmp) and PyUnicode_Check(tmp) then
50665072
s_value := PyUnicodeAsString(tmp);
50675073
Py_XDECREF(tmp);
5074+
if MajorVersion >= 10 then
5075+
begin
5076+
// Get the end offset of the error
5077+
tmp := PyObject_GetAttrString(err_value, 'end_offset' );
5078+
if Assigned(tmp) and PyLong_Check(tmp) then
5079+
i_end_offset := PyLong_AsLong(tmp);
5080+
Py_XDECREF(tmp);
5081+
// Get the end line number of the error
5082+
tmp := PyObject_GetAttrString(err_value, 'end_lineno' );
5083+
if Assigned(tmp) and PyLong_Check(tmp) then
5084+
i_end_line_number := PyLong_AsLong(tmp);
5085+
Py_XDECREF(tmp);
5086+
end;
50685087
end;
50695088
// If all is ok
50705089
if s_value <> '' then
50715090
begin
50725091
with Result do
50735092
begin
5074-
Message := Format('%s: %s (line %d, offset %d): ''%s''', [sType,s_value,i_line_number, i_offset,s_line]);
5075-
EName := sType;
5076-
EValue := s_value;
5077-
EFileName := s_filename;
5078-
ELineNumber := i_line_number;
5079-
EOffset := i_offset;
5080-
ELineStr := s_line;
5093+
Message := Format('%s: %s (line %d, offset %d): ''%s''', [sType,s_value,i_line_number, i_offset,s_line]);
5094+
EName := sType;
5095+
EValue := s_value;
5096+
EFileName := s_filename;
5097+
ELineNumber := i_line_number;
5098+
EOffset := i_offset;
5099+
EEndLineNumber := i_end_line_number;
5100+
EEndOffset := i_end_offset;
5101+
ELineStr := s_line;
50815102
end;
50825103
end
50835104
else

0 commit comments

Comments
 (0)