parsing Python 2.5 conditional expressions

This commit is contained in:
Dmitry Jemerov
2008-02-02 22:43:27 +03:00
parent f91a331014
commit afb2d37447
8 changed files with 140 additions and 0 deletions
@@ -0,0 +1 @@
x = true_value if condition else false_value
@@ -0,0 +1,20 @@
PyFile:ConditionalExpression.py
PyAssignmentStatement
PyReferenceExpression: x
PsiElement(Py:IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyConditionalExpression
PyReferenceExpression: true_value
PsiElement(Py:IDENTIFIER)('true_value')
PsiWhiteSpace(' ')
PsiElement(Py:IF_KEYWORD)('if')
PsiWhiteSpace(' ')
PyReferenceExpression: condition
PsiElement(Py:IDENTIFIER)('condition')
PsiWhiteSpace(' ')
PsiElement(Py:ELSE_KEYWORD)('else')
PsiWhiteSpace(' ')
PyReferenceExpression: false_value
PsiElement(Py:IDENTIFIER)('false_value')
@@ -0,0 +1 @@
[f for f in 1, (lambda x: x if x >= 0 else -1)]
@@ -0,0 +1,52 @@
PyFile:ConditionalParenLambda.py
PyExpressionStatement
PyListCompExpression
PsiElement(Py:LBRACKET)('[')
PyReferenceExpression: f
PsiElement(Py:IDENTIFIER)('f')
PsiWhiteSpace(' ')
PsiElement(Py:FOR_KEYWORD)('for')
PsiWhiteSpace(' ')
PyReferenceExpression: f
PsiElement(Py:IDENTIFIER)('f')
PsiWhiteSpace(' ')
PsiElement(Py:IN_KEYWORD)('in')
PsiWhiteSpace(' ')
PyTupleExpression
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('1')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyParenthesizedExpression
PsiElement(Py:LPAR)('(')
PyLambdaExpression
PsiElement(Py:LAMBDA_KEYWORD)('lambda')
PsiWhiteSpace(' ')
PyParameterList
PyParameter
PsiElement(Py:IDENTIFIER)('x')
PsiElement(Py:COLON)(':')
PsiWhiteSpace(' ')
PyConditionalExpression
PyReferenceExpression: x
PsiElement(Py:IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(Py:IF_KEYWORD)('if')
PsiWhiteSpace(' ')
PyBinaryExpression
PyReferenceExpression: x
PsiElement(Py:IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(Py:GE)('>=')
PsiWhiteSpace(' ')
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('0')
PsiWhiteSpace(' ')
PsiElement(Py:ELSE_KEYWORD)('else')
PsiWhiteSpace(' ')
PyPrefixExpression
PsiElement(Py:MINUS)('-')
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('1')
PsiElement(Py:RPAR)(')')
PsiElement(Py:RBRACKET)(']')
@@ -0,0 +1 @@
[x for x in lambda: True, lambda: False if x()]
@@ -0,0 +1,41 @@
PyFile:LambdaComprehension.py
PyExpressionStatement
PyListCompExpression
PsiElement(Py:LBRACKET)('[')
PyReferenceExpression: x
PsiElement(Py:IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(Py:FOR_KEYWORD)('for')
PsiWhiteSpace(' ')
PyReferenceExpression: x
PsiElement(Py:IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(Py:IN_KEYWORD)('in')
PsiWhiteSpace(' ')
PyTupleExpression
PyLambdaExpression
PsiElement(Py:LAMBDA_KEYWORD)('lambda')
PyParameterList
PsiElement(Py:COLON)(':')
PsiWhiteSpace(' ')
PyReferenceExpression: True
PsiElement(Py:IDENTIFIER)('True')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace(' ')
PyLambdaExpression
PsiElement(Py:LAMBDA_KEYWORD)('lambda')
PyParameterList
PsiElement(Py:COLON)(':')
PsiWhiteSpace(' ')
PyReferenceExpression: False
PsiElement(Py:IDENTIFIER)('False')
PsiWhiteSpace(' ')
PsiElement(Py:IF_KEYWORD)('if')
PsiWhiteSpace(' ')
PyCallExpression: x
PyReferenceExpression: x
PsiElement(Py:IDENTIFIER)('x')
PyArgumentList
PsiElement(Py:LPAR)('(')
PsiElement(Py:RPAR)(')')
PsiElement(Py:RBRACKET)(']')
+1
View File
@@ -0,0 +1 @@
lambda x: 5 if x else 2
+23
View File
@@ -0,0 +1,23 @@
PyFile:LambdaConditional.py
PyExpressionStatement
PyLambdaExpression
PsiElement(Py:LAMBDA_KEYWORD)('lambda')
PsiWhiteSpace(' ')
PyParameterList
PyParameter
PsiElement(Py:IDENTIFIER)('x')
PsiElement(Py:COLON)(':')
PsiWhiteSpace(' ')
PyConditionalExpression
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('5')
PsiWhiteSpace(' ')
PsiElement(Py:IF_KEYWORD)('if')
PsiWhiteSpace(' ')
PyReferenceExpression: x
PsiElement(Py:IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(Py:ELSE_KEYWORD)('else')
PsiWhiteSpace(' ')
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('2')