Repository: Instagram/LibCST (language: python)

Issue:
IndexError when `str(e)` for ParserSyntaxError with native parser
It seems that for the native parser, it's unable to render the exception info like it's used to when using the Python parser.

## Reproduction steps

```python
# Python 3.10.4 (main, Apr  1 2022, 13:25:48) [Clang 13.0.1 ] on darwin
# Type "help", "copyright", "credits" or "license" for more information.
import libcst as cst
expr = "print('hello'\n"
try:
    cst.parse_expression(expr)
except cst.ParserSyntaxError as err:
    print(err)

# Syntax Error @ 2:1.
# Incomplete input. Encountered end of file (EOF), but expected ')'.
#
# print('hello'
#              ^

import os
os.environ["LIBCST_PARSER_TYPE"] = "native"
try:
    cst.parse_expression(expr)
except cst.ParserSyntaxError as err:
    print(err)

# Traceback (most recent call last):
#  File "<stdin>", line 2, in <module>
#  File "/Users/dhruv/projects/remove-print-statements/.venv/lib/python3.10/site-packages/libcst/_parser/entrypoints.py", line 160, in parse_expression
#    result = _parse(
#  File "/Users/dhruv/projects/remove-print-statements/.venv/lib/python3.10/site-packages/libcst/_parser/entrypoints.py", line 55, in _parse
#    return parse(source_str)
# libcst._exceptions.ParserSyntaxError: <exception str() failed>
#
# During handling of the above exception, another exception occurred:
#
# Traceback (most recent call last):
#  File "<stdin>", line 4, in <module>
#  File "/Users/dhruv/projects/remove-print-statements/.venv/lib/python3.10/site-packages/libcst/_exceptions.py", line 154, in __str__
#    context = self.context
#  File "/Users/dhruv/projects/remove-print-statements/.venv/lib/python3.10/site-packages/libcst/_exceptions.py", line 179, in context
#    displayed_column = self.editor_column
#  File "/Users/dhruv/projects/remove-print-statements/.venv/lib/python3.10/site-packages/libcst/_exceptions.py", line 222, in editor_column
#    prefix_str = self._lines[self.raw_line - 1][: self.raw_column]
# IndexError: list index out of range
```

## Information

- `libcst` version: `0.4.1`
- Python version: `3.10.4`
- OS: macOS Monterey 12.3.1


Discussion / hints:
Seems like the returned exception has 0 based lines and columns. Should be easy to fix, I'll look into it over the weekend 

Fix patch:
diff --git a/native/libcst/src/parser/errors.rs b/native/libcst/src/parser/errors.rs
index aae7fdb61..cc58bfa27 100644
--- a/native/libcst/src/parser/errors.rs
+++ b/native/libcst/src/parser/errors.rs
@@ -49,16 +49,20 @@ mod py_error {
                     }
                     _ => vec![""],
                 };
-                let (line, col) = match &e {
+                let (mut line, mut col) = match &e {
                     ParserError::ParserError(err, ..) => {
                         (err.location.start_pos.line, err.location.start_pos.column)
                     }
                     _ => (0, 0),
                 };
+                if line + 1 > lines.len() {
+                    line = lines.len() - 1;
+                    col = 0;
+                }
                 let kwargs = [
                     ("message", e.to_string().into_py(py)),
                     ("lines", lines.into_py(py)),
-                    ("raw_line", line.into_py(py)),
+                    ("raw_line", (line + 1).into_py(py)),
                     ("raw_column", col.into_py(py)),
                 ]
                 .into_py_dict(py);


Test patch:
diff --git a/libcst/_parser/tests/test_parse_errors.py b/libcst/_parser/tests/test_parse_errors.py
index f36d08e7e..b39ea20ed 100644
--- a/libcst/_parser/tests/test_parse_errors.py
+++ b/libcst/_parser/tests/test_parse_errors.py
@@ -172,6 +172,8 @@ def test_parser_syntax_error_str(
     ) -> None:
         with self.assertRaises(cst.ParserSyntaxError) as cm:
             parse_fn()
+        # make sure str() doesn't blow up
+        self.assertIn("Syntax Error", str(cm.exception))
         if not is_native():
             self.assertEqual(str(cm.exception), expected)