Implemented parsing-dependent PSI building for 'import as', 'with ... as' and 'from __future__ import' constructs; added tests.

This commit is contained in:
Dmitry Cheryasov
2008-04-10 19:30:45 +04:00
parent 2b4ae16635
commit 42249bb6a0
6 changed files with 419 additions and 15 deletions
+22
View File
@@ -0,0 +1,22 @@
# import A as B
import A as B
# import A as D, A as DDD
import A as D, A as DDD
# import A.B.C as D, A as DDD
import A.B.C as D, A as DDD
# import as as as
import as as as
# import A
import A
# import A, B, C
import A, B, C
# import A.B.C
import A.B.C
# from A import B, C
from A import B, C
# from A import B as C
from A import B as C
# from A import B as C, X as Y
from A import B as C, X as Y
# from foo import as as as
from foo import as as as
+211
View File
@@ -0,0 +1,211 @@
PyFile:ImportStmt.py
PsiComment(Py:END_OF_LINE_COMMENT)('# import A as B')
PsiWhiteSpace('\n')
PyImportStatement
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: B
PsiElement(Py:IDENTIFIER)('B')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# import A as D, A as DDD')
PsiWhiteSpace('\n')
PyImportStatement
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: D
PsiElement(Py:IDENTIFIER)('D')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: DDD
PsiElement(Py:IDENTIFIER)('DDD')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# import A.B.C as D, A as DDD')
PsiWhiteSpace('\n')
PyImportStatement
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: C
PyReferenceExpression: B
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiElement(Py:DOT)('.')
PsiElement(Py:IDENTIFIER)('B')
PsiElement(Py:DOT)('.')
PsiElement(Py:IDENTIFIER)('C')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: D
PsiElement(Py:IDENTIFIER)('D')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: DDD
PsiElement(Py:IDENTIFIER)('DDD')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# import as as as')
PsiWhiteSpace('\n')
PyImportStatement
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: as
PsiElement(Py:IDENTIFIER)('as')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: as
PsiElement(Py:IDENTIFIER)('as')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# import A')
PsiWhiteSpace('\n')
PyImportStatement
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# import A, B, C')
PsiWhiteSpace('\n')
PyImportStatement
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: B
PsiElement(Py:IDENTIFIER)('B')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: C
PsiElement(Py:IDENTIFIER)('C')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# import A.B.C')
PsiWhiteSpace('\n')
PyImportStatement
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: C
PyReferenceExpression: B
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiElement(Py:DOT)('.')
PsiElement(Py:IDENTIFIER)('B')
PsiElement(Py:DOT)('.')
PsiElement(Py:IDENTIFIER)('C')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# from A import B, C')
PsiWhiteSpace('\n')
PyFromImportStatement
PsiElement(Py:FROM_KEYWORD)('from')
PsiWhiteSpace(' ')
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiWhiteSpace(' ')
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: B
PsiElement(Py:IDENTIFIER)('B')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: C
PsiElement(Py:IDENTIFIER)('C')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# from A import B as C')
PsiWhiteSpace('\n')
PyFromImportStatement
PsiElement(Py:FROM_KEYWORD)('from')
PsiWhiteSpace(' ')
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiWhiteSpace(' ')
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: B
PsiElement(Py:IDENTIFIER)('B')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: C
PsiElement(Py:IDENTIFIER)('C')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# from A import B as C, X as Y')
PsiWhiteSpace('\n')
PyFromImportStatement
PsiElement(Py:FROM_KEYWORD)('from')
PsiWhiteSpace(' ')
PyReferenceExpression: A
PsiElement(Py:IDENTIFIER)('A')
PsiWhiteSpace(' ')
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: B
PsiElement(Py:IDENTIFIER)('B')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: C
PsiElement(Py:IDENTIFIER)('C')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: X
PsiElement(Py:IDENTIFIER)('X')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: Y
PsiElement(Py:IDENTIFIER)('Y')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# from foo import as as as')
PsiWhiteSpace('\n')
PyFromImportStatement
PsiElement(Py:FROM_KEYWORD)('from')
PsiWhiteSpace(' ')
PyReferenceExpression: foo
PsiElement(Py:IDENTIFIER)('foo')
PsiWhiteSpace(' ')
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: as
PsiElement(Py:IDENTIFIER)('as')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyTargetExpression: as
PsiElement(Py:IDENTIFIER)('as')
+9
View File
@@ -0,0 +1,9 @@
# with = 1 # legal identifier
# with = 1
with = 1
# from __future__ import with_statement, nested_scopes
from __future__ import with_statement, nested_scopes
# with x.y(z)[t] as y: pass
with x.y(z)[t] as y: pass
# with = 1 # now illegal
with = 1
+80
View File
@@ -0,0 +1,80 @@
PyFile:WithStatement2.py
PsiComment(Py:END_OF_LINE_COMMENT)('# with = 1 # legal identifier')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# with = 1')
PsiWhiteSpace('\n')
PyAssignmentStatement
PyTargetExpression: with
PsiElement(Py:IDENTIFIER)('with')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('1')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# from __future__ import with_statement, nested_scopes')
PsiWhiteSpace('\n')
PyFromImportStatement
PsiElement(Py:FROM_KEYWORD)('from')
PsiWhiteSpace(' ')
PyReferenceExpression: __future__
PsiElement(Py:IDENTIFIER)('__future__')
PsiWhiteSpace(' ')
PsiElement(Py:IMPORT_KEYWORD)('import')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: with_statement
PsiElement(Py:IDENTIFIER)('with_statement')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyImportElement
PyReferenceExpression: nested_scopes
PsiElement(Py:IDENTIFIER)('nested_scopes')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# with x.y(z)[t] as y: pass')
PsiWhiteSpace('\n')
PyWithStatement
PsiElement(Py:WITH_KEYWORD)('with')
PsiWhiteSpace(' ')
PySubscriptionExpression
PyCallExpression: y
PyReferenceExpression: y
PyReferenceExpression: x
PsiElement(Py:IDENTIFIER)('x')
PsiElement(Py:DOT)('.')
PsiElement(Py:IDENTIFIER)('y')
PyArgumentList
PsiElement(Py:LPAR)('(')
PyReferenceExpression: z
PsiElement(Py:IDENTIFIER)('z')
PsiElement(Py:RPAR)(')')
PsiElement(Py:LBRACKET)('[')
PyReferenceExpression: t
PsiElement(Py:IDENTIFIER)('t')
PsiElement(Py:RBRACKET)(']')
PsiWhiteSpace(' ')
PsiElement(Py:AS_KEYWORD)('as')
PsiWhiteSpace(' ')
PyReferenceExpression: y
PsiElement(Py:IDENTIFIER)('y')
PsiElement(Py:COLON)(':')
PsiWhiteSpace(' ')
PyStatementList
PyPassStatement
PsiElement(Py:PASS_KEYWORD)('pass')
PsiWhiteSpace('\n')
PsiComment(Py:END_OF_LINE_COMMENT)('# with = 1 # now illegal')
PsiWhiteSpace('\n')
PyWithStatement
PsiElement(Py:WITH_KEYWORD)('with')
PsiErrorElement:expression expected
<empty list>
PsiWhiteSpace(' ')
PyStatementList
PsiElement(Py:EQ)('=')
PsiErrorElement:statement expected, found Py:EQ
<empty list>
PsiWhiteSpace(' ')
PyExpressionStatement
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('1')