Commit Graph
167 Commits
Author SHA1 Message Date
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
Mikhail Golubev 5601b6270c PY-31442 Handle multiline expression fragments inside all-triple-quoted f-strings 2018-10-01 12:46:43 +03:00
Mikhail Golubev 99d8ee7bbc PY-31442 Lexer handles line breaks in single quoted f-strings 2018-10-01 12:46:43 +03:00
Mikhail Golubev 479b06eaed PY-31442 Add test cases for various scenarios when f-string is terminated by a line break 2018-10-01 12:46:42 +03:00
Mikhail Golubev cd3122c7c1 PY-31442 Implement "rich" methods of PyFormattedStringNode including decoding
Also fixed the problem that whitespaces inside literal parts of f-strings were
matched as PsiWhitespaces instead of FSTRING_TEXT tokens and updated all relevant
test data.
2018-10-01 12:46:42 +03:00
Mikhail Golubev 68f72f3dd9 PY-31442 Handle f-strings terminated by other string literals in fragments
When the terminating quote is either at the beginning of a string literal or
inside it, either in the given f-string itself or inside a nested one and
either in normal fragment or in a fragment located inside a format part of
another fragment. Normal string literals and nested f-strings are also checked
separately.
2018-10-01 12:46:42 +03:00
Mikhail Golubev 50383b4768 PY-31442 Properly detect end quotes inside literal and format parts of f-strings 2018-10-01 12:46:42 +03:00
Mikhail Golubev 815d919abb PY-31442 Add test cases for various scenarios of preliminary terminated f-strings 2018-10-01 12:46:42 +03:00
Mikhail Golubev 0300a411d6 PY-31442 Parse type conversions (!r/!s/!a) inside fragments
Also, improved handling of incomplete fragments inside f-strings.
2018-10-01 12:46:42 +03:00
Mikhail Golubev 40c1e8b949 PY-31442 Parse format parts of f-string fragments 2018-10-01 12:46:42 +03:00
Mikhail Golubev 81afd74ed9 PY-31442 Started working on format parts of fragments 2018-10-01 12:46:41 +03:00
Mikhail Golubev c13a63958d PY-31442 Parse simplest possible f-strings together with other expressions
- no nested f-strings
- no formatting parts after colon
- no illegal escapes detection
- no quote mismatch detection
2018-10-01 12:46:41 +03:00
Semyon Proshev 96e41895d3 Deprecate Python 2.5 language level. Remove its usages. 2017-12-13 19:44:28 +03:00
Dmitry Trofimov 79ffc852b7 Move test data for unified parsing to separate folder 2017-10-09 21:23:29 +02:00
Dmitry Trofimov 210bf9b175 Unify stubs for all Python language levels (PY-26392)
The cause of the problem was the difference in parsing for different
language levels.

This commit improves error recovery and adds support for stubs for
syntax elements unavailable in older Python versions.
Cases that are covered are necessary for stubs generation
for Python 3.6 standard library. They are discovered by automatic
validation executed by stubs generator in StubsGenerator.kt.

Those are the cases that were fixed:
* A stub for single star argument in Py2 was absent
* Type annotations in Py2 were absent
* Print with end argument in Py2 broke parser
* Exec function as argument in Py2 broke parser
* Async keyword after decorator broke parser

All the cases are listed as test cases in PyUnifiedStubsTest

P.S. It is possible though that more cases will be revealed in future.
2017-10-09 21:23:29 +02:00
Mikhail Golubev 9c3aa66ca4 PY-17017 Comments with greater indent are still included inside suite 2017-10-02 15:20:24 +03:00
Mikhail Golubev 98cc3d928c PY-17017 Properly add DEDENT tokens after a series of trailing comments 2017-10-02 15:20:24 +03:00
Dmitry Trofimov d4c895fbec Fix test data 2017-09-11 19:38:27 +03:00
Mikhail Golubev 8fe04bedbe PY-24389 Allow trailing comma in all parameter lists starting from Python 3.6
Previously it was prohibited in signatures containing varargs and
single stars (delimiting normal and keyword-only parameters).
2017-08-04 14:49:01 +03:00
Andrey VlasovskikhandAndrey Vlasovskikh 91a45bf7ed Restored None, False, True as non-keywords (reserved words) in PY2 (PY-23305, PY-23364)
Typeshed doesn't contain the definitions for them in __builtins__.pyi
so we have to provide types and detect the builtin status for these
words as a special case.
2017-04-17 21:17:35 +03:00
Andrey VlasovskikhandAndrey Vlasovskikh b3eeba17f6 False, True, None made keywords for Python 2 due to typeshed's __builtins__.pyi 2017-02-02 01:24:11 +03:00
Semyon Proshev 2174c9b258 PY-20682 Fixed: await something() as function argument is not recognized by syntax analyzer
Copy `async` flag in ParsingScope.withSuite
2016-12-02 13:54:24 +03:00
Semyon Proshev cee9fd7789 PY-20770 Fixed: Support Python 3.6 asynchronous generators and comprehensions
Add tests for parsing await inside comprehensions
2016-09-30 18:06:20 +03:00
Semyon Proshev e23de0ceb6 PY-20770 Fixed: Support Python 3.6 asynchronous generators and comprehensions
Check for "for" or "async for" while parsing generators, list, dict and set literals
Highlight "async" as keyword in generators, list, dict and set literals
2016-09-30 18:05:19 +03:00
Mikhail Golubev b16311ef60 PY-18972 Initial support of f-string literals
Namely, Python lexer, compatibility inspection and unsupported
features annotator are aware of them now.
2016-09-16 08:16:26 +03:00
Mikhail Golubev 3266460142 PY-20744 Parse PEP-526 variable annotations
Annotation is preserved at the level of assignment nodes similar to
where CPython keeps them in its AST (in special "augassign" nodes).
For type annotations in form "x: int" without variable initialization
special statement PyTypeDefinitionStatement was introduced.
2016-09-16 08:16:26 +03:00
Semyon Proshev 61b92120d7 Assignment to await expressions is forbidden now 2016-07-08 13:47:38 +03:00
Semyon Proshev 673bc32291 PY-19036 Fixed: Using await in a non-asynchronous nested function not marked as a syntax error
Don't inherit async flag in ParsingScope, pass async flag to function parsing
2016-04-18 14:07:04 +03:00
Andrey Vlasovskikh 30c936a46d Fixed warnings for star unpacking in set literals 2015-09-14 15:22:58 +03:00
Andrey Vlasovskikh 045532ee74 Allow PEP 448 **expr syntax in dict literals 2015-09-14 13:48:16 +03:00
Andrey Vlasovskikh caf85e8e71 Fixed parsing decorated async functions and 'await' expressions inside them (PY-16094) 2015-09-08 17:44:21 +03:00
Andrey Vlasovskikh c855959143 Parse and highlight the 'await' keyword (PY-16094) 2015-09-08 14:21:52 +03:00
Andrey Vlasovskikh d616d70c50 Parse and highlight the 'async' keyword (PY-16094)
We had to switch to stack-based parsing contexts in order to be able
to use context-sensitive token filtering for 'async'.

Also this commit fixes the highlighting annotator issue with blinking
names of the functions and blinking 'async'.
2015-09-06 20:04:50 +03:00
Mikhail Golubev 6794f3299c PY-15653 Do not consume open parenthesis after missing identifier in class and function headers 2015-04-21 15:14:25 +03:00
Mikhail Golubev 8f30a5836a PY-15469 Delimiter "->" in Python is parsed as single token
Thanks to that, pressing enter no longer inserts backslash in the
middle of "->" sequence (and such corrupted code is properly
highlighted now on).
2015-04-08 16:28:54 +03:00