Raise an IndentationError from a parse error.
(
vm: &VirtualMachine,
err: &ParseError,
source: &str,
line_index: &LineIndex,
)
| 473 | |
| 474 | /// Raise an IndentationError from a parse error. |
| 475 | fn raise_indentation_error( |
| 476 | vm: &VirtualMachine, |
| 477 | err: &ParseError, |
| 478 | source: &str, |
| 479 | line_index: &LineIndex, |
| 480 | ) -> rustpython_vm::builtins::PyBaseExceptionRef { |
| 481 | let err_lc = line_index.line_column(err.location.start(), source); |
| 482 | let err_line_text = source.full_line_str(err.location.start()); |
| 483 | let err_text = err_line_text.trim_end_matches('\n').trim_end_matches('\r'); |
| 484 | let msg = format!("{}", err.error); |
| 485 | let exc = vm.new_exception_msg( |
| 486 | vm.ctx.exceptions.indentation_error.to_owned(), |
| 487 | msg.clone().into(), |
| 488 | ); |
| 489 | let obj = exc.as_object(); |
| 490 | let _ = obj.set_attr("lineno", vm.ctx.new_int(err_lc.line.get()), vm); |
| 491 | let _ = obj.set_attr("offset", vm.ctx.new_int(err_text.len() as i64 + 1), vm); |
| 492 | let _ = obj.set_attr("msg", vm.ctx.new_str(msg), vm); |
| 493 | let _ = obj.set_attr("filename", vm.ctx.new_str("<string>"), vm); |
| 494 | let _ = obj.set_attr("text", vm.ctx.new_str(err_text), vm); |
| 495 | exc |
| 496 | } |
| 497 | |
| 498 | /// Split an FSTRING_MIDDLE/TSTRING_MIDDLE token containing `{{`/`}}` |
| 499 | /// into multiple unescaped sub-tokens. |
no test coverage detected