Commit Graph

201 Commits

Author SHA1 Message Date
andrey.matveev
ecd113fc12 PY-52930 Support except star
(cherry picked from commit 4d03313cce07e4c3ff4748328cf2e04ba74b8d91)

IJ-MR-24242

GitOrigin-RevId: fa6c1b9077ef78b35c8f3453debcf06bcbc96364
2022-05-18 00:19:37 +00:00
Mikhail Golubev
97b22aaa13 PY-42200 Support parenthesized context managers in Python 3.9+
In case of syntactic ambiguity with previous versions of the grammar, such as
"with (expr)" or "with (expr1, expr2)", PyWithStatement is still parsed as
having its own parentheses, not a parenthesized expression or a tuple as
a single context expression. The latter case, even though syntactically legal,
is still reported by the compatibility inspection in Python <3.9.

These changes also include proper formatter and editing support (e.g. not
inserting backslashes on line breaks inside parentheses), as well as
Complete Current Statement, which now takes possible parentheses into account
while inserting a missing colon.

The changes in the formatter are somewhat ad-hoc, intended to minimize the effect
on other constructs. "With" statement is somewhat special in the sense that it's
the first compound statement (having a statement list) with its own list-like
part in parentheses.

Existing tests on with statement processing were expanded and uniformly named.

Co-authored-by: Semyon Proshev <semyon.proshev@jetbrains.com>

GitOrigin-RevId: 15c33e97f177e81b5ed23891063555df016feb05
2022-05-04 12:31:37 +00:00
Irina Fediaeva
333e20478b PY-48940: Allow unparenthesized assignment expressions within sequence indexes, but not in slices.
(cherry picked from commit c8bfbc4149b840033f9c24a9190860abdd0ff6a8)

IJ-CR-11891

GitOrigin-RevId: 3ce6f98d5b031c705c461505a5c307c0241ce97e
2021-08-10 13:00:59 +00:00
Irina Fediaeva
a86c492a92 PY-48940: Allow unparenthesized assignment expressions within set literals, set comprehensions.
(cherry picked from commit 1ed44bb7a0bde2c7000923c2ed2a671f913eae8f)

IJ-CR-11891

GitOrigin-RevId: bb0ae8626e085e6c9223626137dbdd07e5c084b3
2021-08-10 13:00:58 +00:00
Mikhail Golubev
0db66c81a5 PY-49990 Parse a match statement without a subject as a type declaration
GitOrigin-RevId: 5c6dc8257973dd0f22a5ef8dd5883628205689a7
2021-08-09 14:39:03 +00:00
Mikhail Golubev
20097f7a69 PY-49785 Properly recover from "case" keyword in the middle of a match statement
Not stopping at a statement break token and continuing recovery until a colon,
we considered the subsequent well-formed case clause to be a part of an error
message about a missing pattern, thus, moving the caret to its colon.

GitOrigin-RevId: f4ee0e12876960e989de3dee89925b65e3cf2339
2021-07-19 16:29:15 +00:00
Mikhail Golubev
e1b52ae759 PY-48008 Improve test coverage of match statements parsing
GitOrigin-RevId: 347185106d7fec7117c31b10fa24b709a3b0da42
2021-06-24 16:26:19 +00:00
Mikhail Golubev
70efe3108f PY-48008 Report missing subject expression in match statements
GitOrigin-RevId: 2c49ea19ac0fb5bdda966e4077c45321c397df8a
2021-06-24 16:26:18 +00:00
Mikhail Golubev
98d196aec6 PY-48009 Add automatic indent inside match statements
Namely, for their case clauses and inner comments.

Right now, each of them is indented on its own, as a separate formatting block.
It's still not entirely clear whether we should have a dedicated indented
container element for case clauses, similar to PyStatementList for statements.
It might simplify the formatter and some editing actions, but cause confusion
between the two container elements.

GitOrigin-RevId: 69184d2f8f78e2e113e8f40a310bb13ac0b5e71a
2021-05-24 10:28:35 +00:00
Mikhail Golubev
639b8d1029 PY-48008 Implement parsing of PEP-634 match statements
All the corresponding PSI elements now have empty interfaces. The API will be
"beefed up" as we start adding actual processing of them in the code insight
(e.g. for the upcoming CFG and inspections).

The trickiest part of the parsing was the recovery. Patterns allow only
a limited subset of expression syntax, but I tried to sensibly consume and report
everything else (not building PSI for it). So that if user starts typing more
general expressions in the midst of a pattern, we still give meaningful error
messages. It seems a likely cause of errors when the feature first rolls out in
Python 3.10.

GitOrigin-RevId: fae40034964e4a25d91dab06a43d3fc07225d9c7
2021-05-24 10:28:29 +00:00
Andrey Vlasovskikh
dfbab3186a PY-47974 Fixed missing components for running PythonConsoleParsingTest
GitOrigin-RevId: 7391ba5f43c770ebbc1cbbcde8b72387c5c90ea7
2021-04-08 00:23:08 +00:00
Andrey Vlasovskikh
4bd67d428d PY-47974 Parse single string literal in Python console as string, not as docstring
We assumed that if the first token of a Python file is a string literal, then it's a docstring. It's not the case for the Python console, where each input is a separate "file".

Now we pass the `PythonLexerKind` to the `PythonLexer` so that we can parse string literals differently if we are in the console "file".

I've also added Cython as a lexical kind for the Python lexer, since there is at least one place in the lexical rules that is specific to Cython. Also we have separate lexer subclasses for Cython, so having it expressed as a kind for the JFlex rules seems logical, even if we don't use it right now.

GitOrigin-RevId: f5e34fa2dc3b3da84cacf6cee69a4ba0ee674ad5
2021-04-07 22:34:46 +00:00
Mikhail Golubev
de08c2a947 Fix Python tests after the proofreading
GitOrigin-RevId: 2f6eb873d6321ef00d293377ec2c97195f72da21
2020-11-30 22:17:55 +00:00
Semyon Proshev
48a952a327 Make parser stricter for for statements and expressions (PY-36478)
Now it more follows original python grammar.

GitOrigin-RevId: 199f30b819c85a4eba5cab9b3f67fbf1bb7f18b6
2020-11-24 17:35:00 +00:00
Semyon Proshev
9335c066f5 Make parser stricter for assignment expressions (PY-33886, PY-36478)
Now it more follows original python grammar.

GitOrigin-RevId: f2b45554d16ff87d946950591f0e92fedcfdfaf0
2020-11-24 17:34:59 +00:00
Mikhail Golubev
91d49d6c87 i18n: Extract Python parsing errors, fix their capitalization and format
GitOrigin-RevId: a7374f1cb1358005b371fcfdeb743a24e04e1fbf
2020-08-17 16:32:09 +00:00
Mikhail Golubev
ed4b1332dc PY-32864 Automatically merge f-string text tokens
It not only makes AST of f-string nodes simpler and more obvious to work with,
but, in general, is also better supported by various platform functionality that
assumes that raw text parts of string literals are not broken into multiple
elements.

GitOrigin-RevId: 931d1ea4c09d145e763aed839dcb4acbb3e43ec7
2020-08-17 11:12:03 +00:00
Lada Gagina
2e617b803c IDEA-CR-63687: PY-41305 Add PEP 614 support
Allows to use any expression as a decorator

GitOrigin-RevId: e92af1ebd2c4d7024971fd4542bfe52640faaa26
2020-06-17 00:30:49 +03:00
Semyon Proshev
5636d2ed7c Update tests after wrapping assigned value into parenthesis while mapping to targets (PY-40814)
GitOrigin-RevId: 74f47b126b61459383186d691a4bf3dfab09edda
2020-02-28 14:02:40 +00:00
Semyon Proshev
8f58988590 i18n
GitOrigin-RevId: c6b70355ca538e522a1b896f412c972fe7aa56e9
2020-02-13 16:19:54 +00:00
Mikhail Golubev
be2d55e603 PY-32123 Ignore escape sequences in raw f-strings by adding special token type for their text
GitOrigin-RevId: 0b15201c60ac56daa45f22bb5ff3c1f8836efee3
2020-01-28 16:04:27 +00:00
Semyon Proshev
8d1b70c5bb Drop psi builder cache on pushing or popping parsing scope (PY-36167)
Since builder could cache something related to the current scope (e.g. token type)

GitOrigin-RevId: ffabda058dac874bd9187fa27d30b823f782fcf6
2019-11-07 02:40:58 +00:00
Semyon Proshev
121f06d991 Avoid parsing RHS of assignment expression as target (PY-33886, PY-36479)
GitOrigin-RevId: 127743a6386b8155ba131fa7f249c761598880e1
2019-08-13 17:04:49 +03:00
Semyon Proshev
ba8411f567 Better handling of incomplete assignment expressions (PY-36479)
Create assignment expression even if its LHS or RHS is invalid.

GitOrigin-RevId: 6905a3b255f0c1fad576049265e39c0434f2d8e3
2019-08-13 17:04:49 +03:00
Semyon Proshev
e13675f384 Fix parsing assignment expressions inside f-strings (PEP 572) (PY-33886)
Every expression on top-level inside f-string that could be considered as an assignment expression is actually a format expression.

GitOrigin-RevId: a375543c80d549d5c08166f33b401206ab31f8b8
2019-07-02 06:52:16 +03:00
Semyon Proshev
ccc2156cf9 Add parsing for assignment expressions (PEP 572) (PY-33886)
Highlight expressions that are invalid by grammar or unacceptable in runtime
Highlight expressions in pythons < 3.8

GitOrigin-RevId: 89acec9db5b3a931da31c33778185e147240ec01
2019-07-02 06:52:16 +03:00
Lada Gagina
3b991b20ca PY-36009 Add support of '=' for debugging in f-strings
GitOrigin-RevId: 79314512860158a4c535103ee2ac9fee43d30d0d
2019-07-02 06:52:16 +03:00
Rustam Vishnyakov
123242c4b2 EditorConfig documentation test
GitOrigin-RevId: fd52ace3d7a32ecd02c2c5ab90e077967604c15e
2019-06-16 04:03:21 +03:00
Egor Zhdan
c1813cfb52 Cleanup: NotNull/Nullable
GitOrigin-RevId: b8e892f32ea84c2115973155dba7127b892cc36e
2019-06-16 04:02:08 +03:00
Anna Kozlova
91f7445298 constructor reference: don't ignore constructor parameters during method reference inference (IDEA-185578)
GitOrigin-RevId: e836468e05db28157713e9edd3c70382f8ecdebc
2019-06-13 03:15:49 +03:00
Egor Zhdan
39d2d77155 Cleanup: NotNull/Nullable
GitOrigin-RevId: b8e892f32ea84c2115973155dba7127b892cc36e
2019-06-13 03:14:35 +03:00
Julia Beliaeva
3fee046d20 [vcs-log] cleanup RootCellRenderer
GitOrigin-RevId: bba216626193ac756cd133b8ae9bc4e577abea42
2019-06-10 04:10:14 +03:00
Eldar Abusalimov
dcaeb8f8c7 OC-4061: ApplicationUtil: Make runWithCheckCanceled() return result
GitOrigin-RevId: 3aa9f23cc5097e644eddf82a4faca669759b4760
2019-06-10 04:09:35 +03:00
Semyon Proshev
d7e8ebf1ef Parsing for positional-only parameters (PEP 570) (PY-35512)
GitOrigin-RevId: c568de8ebdb4f9b73cd5e2f9cb4a17184092ee22
2019-06-04 19:11:50 +03:00
Mikhail Golubev
6354daae42 PY-31442 Rename PyRichStringNode to PyStringElement with inheritors
so as not to cause confusion with ASTNode. Also additionally rename
PyLiteralStringElement to PyPlainStringElement, again, not to confuse
users with subtle "string literal" vs. "literal string" differences
in meaning.
2018-10-01 12:46:48 +03:00
Mikhail Golubev
c5f0bde323 PY-31442 In recovery phase of the parser treat FSTRING_END as STATEMENT_BREAK
This token shouldn't get under PsiError node and must be propagated further up
to properly terminate containing f-string.
2018-10-01 12:46:47 +03:00
Mikhail Golubev
16dea81d1a PY-31442 Fix detection of terminating quotes inside triple-quoted f-strings 2018-10-01 12:46:47 +03:00
Mikhail Golubev
6c49b63b11 PY-31442 Better handling of single backslashes (e.g. before braces) in literal parts
There is actually no need to match them together with braces and then return
the second character back to the stream. The longest match rule will ensure
that all allowed escape sequences will be recognised as one unit, so it seems
safe to match backslash individually for all remaining cases.
2018-10-01 12:46:45 +03:00
Mikhail Golubev
2e8b9f7a9f PY-31442 Handle hash signs in literal parts of f-strings
Made the corresponding states of the lexer exclusive so that the pattern
for line comments doesn't match literal fragments starting with a hash sign
as the longest (together with closing braces and quotes). It also means that
we need to replicate the BAD_CHARACTER rule in these states as a fallback
pattern for unmatched input.
2018-10-01 12:46:45 +03:00
Mikhail Golubev
1e527a9ba4 PY-31442 Shorter parser error for incomplete fragments terminated by closing quotes
In these cases one probably doesn't want to either specify a type conversion character
or add a format part and has just forgotten a closing brace.
2018-10-01 12:46:45 +03:00
Mikhail Golubev
b09241cb09 PY-31442 Include comments and whitespaces inside fragments
It's beneficial for two reasons: it allows us to avoid occasional
PsiWhitespaces at the end of incomplete fragments and also we
can now better report illegal line comments this way, because even though
they still terminate f-strings they are now under the corresponding AST
nodes for expression fragments and can be processed by the annotator
in the same fashion.
2018-10-01 12:46:45 +03:00
Mikhail Golubev
2f9b1c62ff PY-31442 Migrate FStringsAnnotator to the new f-strings AST
Also tweaked interfaces of PyFormattedStringNode and PyFStringFragment.
2018-10-01 12:46:45 +03:00
Mikhail Golubev
2287a27ed0 PY-31442 Handles escape sequences in format parts and backslashes before curly braces 2018-10-01 12:46:44 +03:00
Mikhail Golubev
88119d9c59 PY-31442 Handle all types of terminating quotes in fragment format parts 2018-10-01 12:46:44 +03:00
Mikhail Golubev
5691edb8b4 PY-31442 Lexer can handle named unicode escapes inside f-strings 2018-10-01 12:46:44 +03:00
Mikhail Golubev
76e672e243 PY-31442 Better reporting of mismatched/missing closing quotes 2018-10-01 12:46:44 +03:00
Mikhail Golubev
0d0ea521c8 PY-31442 Add tests on handling of line comments inside fragments 2018-10-01 12:46:44 +03:00
Mikhail Golubev
77e47676b4 PY-31442 Better recovery inside expression fragments
Including cases when there is a dangling backslash inside an expression.
2018-10-01 12:46:44 +03:00
Mikhail Golubev
3767218928 PY-31442 Add a test on parsing of empty f-strings 2018-10-01 12:46:43 +03:00
Mikhail Golubev
f8986ccb61 PY-31442 Add a test case when all kinds of f-strings are nested into each other 2018-10-01 12:46:43 +03:00