Skip to content

Commit 82414a5

Browse files
committed
Manage most cases of DictionaryComprehension
1 parent 0f7beb1 commit 82414a5

20 files changed

Lines changed: 889 additions & 32 deletions

‎src/FAST-Python-Model-Generator/FASTPythonMetamodelGenerator.class.st‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ Class {
154154
'tDefinition',
155155
'tDecoratorExpression',
156156
'tWithElseClause',
157-
'tWithComment'
157+
'tWithComment',
158+
'collectionSplat',
159+
'tCanBeSplatExpression'
158160
],
159161
#category : 'FAST-Python-Model-Generator',
160162
#package : 'FAST-Python-Model-Generator'
@@ -203,6 +205,7 @@ FASTPythonMetamodelGenerator >> defineClasses [
203205
classDefinition withTesting.
204206
classPattern := builder ensureClassNamed: #ClassPattern."Todo"
205207
collectionInitializer := builder ensureClassNamed: #CollectionInitializer.
208+
(collectionSplat := builder ensureClassNamed: #CollectionSplat) comment: 'In Python a collection (list or dictionary) splat is the unpacking of a collection in a call or in the definition of another definition like `[ *list , 4 ]` or `func(*list)`'.
206209
comment := builder ensureClassNamed: #Comment."Todo"
207210
comparisonOperator := builder ensureClassNamed: #ComparisonOperator.
208211
complex := builder ensureClassNamed: #Complex.
@@ -314,7 +317,6 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
314317

315318
entity --|> tEntity.
316319
self flag: #todo. "The next two line are WRONG and NEEDS to be reviewed but we currently need it because else everything will break until the MM is in a better state."
317-
entity --|> tExpression.
318320
entity --|> tStatement.
319321
entity --|> tWithComment.
320322

@@ -327,16 +329,19 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
327329

328330
attribute --|> expression.
329331
attribute --|> tDecoratorExpression.
332+
attribute --|> tCanBeSplatExpression.
330333

331334
await --|> tStatement.
332335

333336
binaryOperator --|> operator.
334337
binaryOperator --|> tBinaryExpression.
338+
binaryOperator --|> tCanBeSplatExpression.
335339

336340
block --|> tStatementBlock.
337341

338342
booleanOperator --|> operator.
339343
booleanOperator --|> tBinaryExpression. "I am not 100% sure this is the best trait to use but it seems to work well for now"
344+
booleanOperator --|> tCanBeSplatExpression.
340345

341346
boolean --|> literal.
342347
boolean --|> tBooleanLiteral.
@@ -346,11 +351,14 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
346351
call --|> expression.
347352
call --|> tInvocation.
348353
call --|> tDecoratorExpression.
354+
call --|> tCanBeSplatExpression.
349355

350356
classDefinition --|> tNamedBehaviouralEntity.
351357
classDefinition --|> tDefinition.
352358

353359
collectionInitializer --|> expression.
360+
361+
collectionSplat --|> expression.
354362

355363
comment --|> tComment.
356364

@@ -369,9 +377,12 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
369377
deleteStatement --|> statement.
370378

371379
dictionary --|> collectionInitializer.
380+
dictionary --|> tCanBeSplatExpression.
372381

373382
dictionaryComprehension --|> expression.
374383
dictionaryComprehension --|> tComprehension.
384+
385+
dictionarySplat --|> collectionSplat.
375386

376387
elseClause --|> block.
377388

@@ -404,6 +415,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
404415

405416
identifier --|> expression.
406417
identifier --|> tDecoratorExpression.
418+
identifier --|> tCanBeSplatExpression.
407419

408420
ifClause --|> expression. "This is wrong! I am just here temporarily until we rework the relation to the for in clause (I need to be able to be a clause of a list comprehension)"
409421

@@ -432,6 +444,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
432444
listComprehension --|> expression.
433445
listComprehension --|> tComprehension.
434446

447+
listSplat --|> collectionSplat.
448+
435449
literal --|> expression.
436450
literal --|> tLiteral.
437451

@@ -479,6 +493,9 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
479493

480494
subscript --|> expression.
481495
subscript --|> tDecoratorExpression.
496+
subscript --|> tCanBeSplatExpression.
497+
498+
tComprehension --|> tCanBeSplatExpression.
482499

483500
thenClause --|> block.
484501

@@ -548,6 +565,8 @@ FASTPythonMetamodelGenerator >> defineRelations [
548565

549566
((collectionInitializer property: #initializers) comment: 'Each initializer defines one element.')
550567
<>-* ((expression property: #collectionInitializer) comment: 'The owner of the expression').
568+
569+
(collectionSplat property: #expression) <>- (tCanBeSplatExpression property: #parentSplat).
551570

552571
((comparisonOperator property: #operands) comment:
553572
'List of the operands of the comparison operands. For example if we have `a == b != c`, it will be a, b and c.')
@@ -640,13 +659,20 @@ FASTPythonMetamodelGenerator >> defineRelations [
640659
{ #category : 'definition' }
641660
FASTPythonMetamodelGenerator >> defineTraits [
642661

643-
super defineTraits. "Entity"
644-
tEntity := self remoteTrait: #TEntity withPrefix: #FAST. "FAST-Python"
662+
super defineTraits.
663+
664+
"Entity"
665+
tEntity := self remoteTrait: #TEntity withPrefix: #FAST.
666+
667+
"FAST-Python"
668+
tCanBeSplatExpression := (builder newTraitNamed: #TCanBeSplatExpression) comment: 'My users are expressions that can be in a collection splat. For example in `[ *getList(), 3 ]`, we have a list splat on the call `getList()`. Get list, is the expression of the splat.'.
645669
tComprehension := builder newTraitNamed: #TComprehension.
646670
tDefinition := builder newTraitNamed: #TDefinition.
647671
(tDecoratorExpression := builder newTraitNamed: #TDecoratorExpression) comment: 'I represent an entity that *can* be the expression of a decorator.'.
648672
tUnaryOperator := builder newTraitNamed: #TUnaryOperator.
649-
tWithElseClause := builder newTraitNamed: #TWithElseClause. "Remotes"
673+
tWithElseClause := builder newTraitNamed: #TWithElseClause.
674+
675+
"Remotes"
650676
tAssignment := self remoteTrait: #TAssignment withPrefix: #FAST.
651677
tBinaryExpression := self remoteTrait: #TBinaryExpression withPrefix: #FAST.
652678
tBooleanLiteral := self remoteTrait: #TBooleanLiteral withPrefix: #FAST.

‎src/FAST-Python-Model/FASTPyAttributeAccess.class.st‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
88
| `parentDeclarator` | `FASTPyTDecoratorExpression` | `expression` | `FASTPyDecorator` | |
9+
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
910
1011
### Children
1112
| Relation | Origin | Opposite | Type | Comment |
@@ -19,8 +20,8 @@
1920
Class {
2021
#name : 'FASTPyAttributeAccess',
2122
#superclass : 'FASTPyExpression',
22-
#traits : 'FASTPyTDecoratorExpression',
23-
#classTraits : 'FASTPyTDecoratorExpression classTrait',
23+
#traits : 'FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
24+
#classTraits : 'FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
2425
#instVars : [
2526
'#attribute => FMOne type: #FASTPyVariable opposite: #attributeOwner',
2627
'#object => FMOne type: #FASTPyExpression opposite: #attributeObjectOwner'

‎src/FAST-Python-Model/FASTPyBinaryOperator.class.st‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| `parentExpression` | `FASTTExpression` | `expression` | `FASTTUnaryExpression` | Parent (unary) expression|
1515
| `parentExpressionLeft` | `FASTTExpression` | `leftOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am left side|
1616
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
17+
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
1718
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
1819
1920
### Children
@@ -36,8 +37,8 @@
3637
Class {
3738
#name : 'FASTPyBinaryOperator',
3839
#superclass : 'FASTPyOperator',
39-
#traits : 'FASTTBinaryExpression',
40-
#classTraits : 'FASTTBinaryExpression classTrait',
40+
#traits : 'FASTPyTCanBeSplatExpression + FASTTBinaryExpression',
41+
#classTraits : 'FASTPyTCanBeSplatExpression classTrait + FASTTBinaryExpression classTrait',
4142
#category : 'FAST-Python-Model-Entities',
4243
#package : 'FAST-Python-Model',
4344
#tag : 'Entities'

‎src/FAST-Python-Model/FASTPyBooleanOperator.class.st‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| `parentExpression` | `FASTTExpression` | `expression` | `FASTTUnaryExpression` | Parent (unary) expression|
1515
| `parentExpressionLeft` | `FASTTExpression` | `leftOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am left side|
1616
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
17+
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
1718
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
1819
1920
### Children
@@ -36,8 +37,8 @@
3637
Class {
3738
#name : 'FASTPyBooleanOperator',
3839
#superclass : 'FASTPyOperator',
39-
#traits : 'FASTTBinaryExpression',
40-
#classTraits : 'FASTTBinaryExpression classTrait',
40+
#traits : 'FASTPyTCanBeSplatExpression + FASTTBinaryExpression',
41+
#classTraits : 'FASTPyTCanBeSplatExpression classTrait + FASTTBinaryExpression classTrait',
4142
#category : 'FAST-Python-Model-Entities',
4243
#package : 'FAST-Python-Model',
4344
#tag : 'Entities'

‎src/FAST-Python-Model/FASTPyCall.class.st‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| `parentExpression` | `FASTTExpression` | `expression` | `FASTTUnaryExpression` | Parent (unary) expression|
1616
| `parentExpressionLeft` | `FASTTExpression` | `leftOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am left side|
1717
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
18+
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
1819
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
1920
2021
### Children
@@ -37,8 +38,8 @@
3738
Class {
3839
#name : 'FASTPyCall',
3940
#superclass : 'FASTPyExpression',
40-
#traits : 'FASTPyTDecoratorExpression + FASTTInvocation',
41-
#classTraits : 'FASTPyTDecoratorExpression classTrait + FASTTInvocation classTrait',
41+
#traits : 'FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression + FASTTInvocation',
42+
#classTraits : 'FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait + FASTTInvocation classTrait',
4243
#instVars : [
4344
'#callee => FMOne type: #FASTPyExpression opposite: #caller'
4445
],
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"
2+
In Python a collection (list or dictionary) splat is the unpacking of a collection in a call or in the definition of another definition like `[ *list , 4 ]` or `func(*list)`
3+
4+
## Relations
5+
======================
6+
7+
### Children
8+
| Relation | Origin | Opposite | Type | Comment |
9+
|---|
10+
| `expression` | `FASTPyCollectionSplat` | `parentSplat` | `FASTPyTCanBeSplatExpression` | |
11+
12+
13+
14+
"
15+
Class {
16+
#name : 'FASTPyCollectionSplat',
17+
#superclass : 'FASTPyExpression',
18+
#instVars : [
19+
'#expression => FMOne type: #FASTPyTCanBeSplatExpression opposite: #parentSplat'
20+
],
21+
#category : 'FAST-Python-Model-Entities',
22+
#package : 'FAST-Python-Model',
23+
#tag : 'Entities'
24+
}
25+
26+
{ #category : 'meta' }
27+
FASTPyCollectionSplat class >> annotation [
28+
29+
<FMClass: #CollectionSplat super: #FASTPyExpression>
30+
<package: #'FAST-Python-Model'>
31+
<generated>
32+
^ self
33+
]
34+
35+
{ #category : 'accessing' }
36+
FASTPyCollectionSplat >> expression [
37+
"Relation named: #expression type: #FASTPyTCanBeSplatExpression opposite: #parentSplat"
38+
39+
<generated>
40+
^ expression
41+
]
42+
43+
{ #category : 'accessing' }
44+
FASTPyCollectionSplat >> expression: anObject [
45+
46+
<generated>
47+
expression := anObject
48+
]
49+
50+
{ #category : 'navigation' }
51+
FASTPyCollectionSplat >> expressionGroup [
52+
<generated>
53+
<navigation: 'Expression'>
54+
^ MooseSpecializedGroup with: self expression
55+
]

‎src/FAST-Python-Model/FASTPyDictionary.class.st‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
9+
10+
11+
12+
"
113
Class {
214
#name : 'FASTPyDictionary',
315
#superclass : 'FASTPyCollectionInitializer',
16+
#traits : 'FASTPyTCanBeSplatExpression',
17+
#classTraits : 'FASTPyTCanBeSplatExpression classTrait',
418
#category : 'FAST-Python-Model-Entities',
519
#package : 'FAST-Python-Model',
620
#tag : 'Entities'

‎src/FAST-Python-Model/FASTPyDictionaryComprehension.class.st‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
## Relations
33
======================
44
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
9+
510
### Children
611
| Relation | Origin | Opposite | Type | Comment |
712
|---|

‎src/FAST-Python-Model/FASTPyDictionarySplat.class.st‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Class {
22
#name : 'FASTPyDictionarySplat',
3-
#superclass : 'FASTPyEntity',
3+
#superclass : 'FASTPyCollectionSplat',
44
#category : 'FAST-Python-Model-Entities',
55
#package : 'FAST-Python-Model',
66
#tag : 'Entities'
@@ -9,7 +9,7 @@ Class {
99
{ #category : 'meta' }
1010
FASTPyDictionarySplat class >> annotation [
1111

12-
<FMClass: #DictionarySplat super: #FASTPyEntity>
12+
<FMClass: #DictionarySplat super: #FASTPyCollectionSplat>
1313
<package: #'FAST-Python-Model'>
1414
<generated>
1515
^ self

‎src/FAST-Python-Model/FASTPyEntity.class.st‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,8 @@
55
### Parents
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
8-
| `argumentOwner` | `FASTTExpression` | `arguments` | `FASTTWithArguments` | my owner|
9-
| `assignedIn` | `FASTTExpression` | `expression` | `FASTTAssignment` | Optional assignment where this expression is used|
10-
| `expressionStatementOwner` | `FASTTExpression` | `expression` | `FASTTExpressionStatement` | The expression statement that own me (if it's the case|
118
| `genericParent` | `FASTPyEntity` | `genericChildren` | `FASTPyEntity` | |
12-
| `pairKeyOwner` | `FASTTExpression` | `key` | `FASTPyPair` | |
13-
| `pairValueOwner` | `FASTTExpression` | `value` | `FASTPyPair` | |
14-
| `parentConditional` | `FASTTExpression` | `condition` | `FASTTWithCondition` | Optional condition statement/expression where this expression is used|
15-
| `parentExpression` | `FASTTExpression` | `expression` | `FASTTUnaryExpression` | Parent (unary) expression|
16-
| `parentExpressionLeft` | `FASTTExpression` | `leftOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am left side|
17-
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
189
| `parentLoopStatement` | `FASTTStatement` | `body` | `FASTTLoopStatement` | Optional loop of which this statement is the body|
19-
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
2010
| `statementContainer` | `FASTTStatement` | `statements` | `FASTTStatementBlock` | Block containing this statement.|
2111
2212
### Children
@@ -38,8 +28,8 @@
3828
Class {
3929
#name : 'FASTPyEntity',
4030
#superclass : 'MooseEntity',
41-
#traits : 'FASTTEntity + FASTTExpression + FASTTStatement + FASTTWithComments',
42-
#classTraits : 'FASTTEntity classTrait + FASTTExpression classTrait + FASTTStatement classTrait + FASTTWithComments classTrait',
31+
#traits : 'FASTTEntity + FASTTStatement + FASTTWithComments',
32+
#classTraits : 'FASTTEntity classTrait + FASTTStatement classTrait + FASTTWithComments classTrait',
4333
#instVars : [
4434
'#genericChildren => FMMany type: #FASTPyEntity opposite: #genericParent',
4535
'#genericParent => FMOne type: #FASTPyEntity opposite: #genericChildren'
@@ -167,6 +157,13 @@ FASTPyEntity >> isClassDefinition [
167157
^ false
168158
]
169159

160+
{ #category : 'testing' }
161+
FASTPyEntity >> isExpression [
162+
163+
<generated>
164+
^ false
165+
]
166+
170167
{ #category : 'testing' }
171168
FASTPyEntity >> isInvocation [
172169

0 commit comments

Comments
 (0)