Skip to content

Commit 6f62541

Browse files
committed
Begin management of with_statement (WIP)
I still need to add the two new traits on all the classes that should use it I also unified some variable names
1 parent 4d8afdc commit 6f62541

13 files changed

Lines changed: 411 additions & 255 deletions

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ Class {
111111
'unionPattern',
112112
'unionType',
113113
'whileStatement',
114-
'withClause',
115-
'withItem',
116114
'withStatement',
117115
'yield',
118116
'tComment',
@@ -155,7 +153,10 @@ Class {
155153
'tWithElseClause',
156154
'tWithComment',
157155
'collectionSplat',
158-
'tCanBeSplatExpression'
156+
'tCanBeSplatExpression',
157+
'tAsPatternTarget',
158+
'tAsPatternSource',
159+
'tWithStatementItem'
159160
],
160161
#category : 'FAST-Python-Model-Generator',
161162
#package : 'FAST-Python-Model-Generator'
@@ -301,8 +302,6 @@ FASTPythonMetamodelGenerator >> defineClasses [
301302
unionType := builder ensureClassNamed: #UnionType."Todo"
302303
variable := builder ensureClassNamed: #Variable. "To review"
303304
whileStatement := builder ensureClassNamed: #WhileStatement.
304-
withClause := builder ensureClassNamed: #WithClause."Todo"
305-
withItem := builder ensureClassNamed: #WithItem."Todo"
306305
withStatement := builder ensureClassNamed: #WithStatement."Todo"
307306
yield := builder ensureClassNamed: #Yield"Todo"
308307
]
@@ -319,6 +318,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
319318
"Adding a bunch of traits in errors to not interupt the parsing much if we have an error."
320319
_ERROR --|> expression.
321320

321+
asPattern --|> tWithStatementItem.
322+
322323
assignment --|> statement.
323324
assignment --|> tAssignment.
324325

@@ -351,6 +352,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
351352
call --|> tInvocation.
352353
call --|> tDecoratorExpression.
353354
call --|> tCanBeSplatExpression.
355+
call --|> tAsPatternSource.
354356

355357
classDefinition --|> statement.
356358
classDefinition --|> tDefinition.
@@ -415,6 +417,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
415417
identifier --|> expression.
416418
identifier --|> tDecoratorExpression.
417419
identifier --|> tCanBeSplatExpression.
420+
identifier --|> tAsPatternTarget.
418421

419422
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)"
420423

@@ -513,7 +516,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
513516
whileStatement --|> tConditionalStatement.
514517
whileStatement --|> tLoopStatement.
515518

516-
withStatement --|> statement
519+
withStatement --|> statement.
520+
withStatement --|> tStatementBlock
517521
]
518522

519523
{ #category : 'definition' }
@@ -549,16 +553,20 @@ FASTPythonMetamodelGenerator >> defineRelations [
549553

550554
(entity property: #genericChildren) <>-* (entity property: #genericParent).
551555

556+
(asPattern property: #target) <>- (tAsPatternTarget property: #parentAsPatternTarget).
557+
558+
(asPattern property: #source) <>- (tAsPatternSource property: #parentAsPatternSource).
559+
560+
((assertStatement property: #expressions) comment: 'The expressions asserted')
561+
<>-* ((expression property: #parentAssertStatement) comment: 'The assert statement that own the expression (if it''s the case)').
562+
552563
((attribute property: #object) comment:
553564
'I am the receiver of the attribute. I can be multiple things such as a variable, a call, another attribute access, a primitive type, a subscript...')
554565
<>- ((expression property: #attributeObjectOwner) comment: 'My parent if I define the object of an attribute access (if it''s the case).').
555566

556567
((attribute property: #attribute) comment: 'The variable been accessed')
557568
<>- ((variable property: #attributeOwner) comment: 'The attribute access accessing me (if it''s the case)').
558569

559-
((assertStatement property: #expressions) comment: 'The expressions asserted')
560-
<>-* ((expression property: #parentAssertStatement) comment: 'The assert statement that own the expression (if it''s the case)').
561-
562570
(await property: #expression) <>- (expression property: #parentAwait).
563571

564572
((call property: #callee) comment:
@@ -567,13 +575,13 @@ FASTPythonMetamodelGenerator >> defineRelations [
567575

568576
((collectionInitializer property: #initializers) comment: 'Each initializer defines one element.')
569577
<>-* ((expression property: #collectionInitializer) comment: 'The owner of the expression').
570-
578+
571579
(collectionSplat property: #expression) <>- (tCanBeSplatExpression property: #parentSplat).
572580

573581
((comparisonOperator property: #operands) comment:
574582
'List of the operands of the comparison operands. For example if we have `a == b != c`, it will be a, b and c.')
575583
<>-* ((expression property: #parentComparisonOperator) comment: 'Parent comparison expression of which I am.').
576-
584+
577585
(concatenatedString property: #strings) <>-* (string property: #parentConcatenatedString).
578586

579587
(conditionalExpression property: #thenExpression) <>- (expression property: #conditionalExpressionThenOwner).
@@ -627,7 +635,7 @@ FASTPythonMetamodelGenerator >> defineRelations [
627635
(pair property: #value) <>- (tExpression property: #pairValueOwner).
628636

629637
(patternList property: #elements) <>-* (expression property: #patternListOwner).
630-
638+
631639
(printStatement property: #expressions) <>-* (expression property: #prarentPrintStatement).
632640

633641
((slice property: #components) comment: 'The components are the expressions between the `:` of a slice.')
@@ -652,7 +660,9 @@ FASTPythonMetamodelGenerator >> defineRelations [
652660
((tUnaryOperator property: #argument) comment: 'Expression influanced by the unary operator..')
653661
<>- ((expression property: #parentUnaryOperator) comment: 'Parent unary operator in which I am.').
654662

655-
(tWithElseClause property: #elseClause) <>- (elseClause property: #ifStatementOwner)
663+
(tWithElseClause property: #elseClause) <>- (elseClause property: #ifStatementOwner).
664+
665+
(withStatement property: #items) <>-* (tWithStatementItem property: #parentWithClauseItem)
656666
]
657667

658668
{ #category : 'definition' }
@@ -664,11 +674,14 @@ FASTPythonMetamodelGenerator >> defineTraits [
664674
tEntity := self remoteTrait: #TEntity withPrefix: #FAST.
665675

666676
"FAST-Python"
677+
tAsPatternTarget := (builder newTraitNamed: #TAsPatternTarget) comment: 'I represent an entity that could be the alias/target of an as pattern.'.
678+
tAsPatternSource := (builder newTraitNamed: #TAsPatternSource) comment: 'I represent an entity that could be aliased in an as pattern.'.
667679
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.'.
668680
tComprehension := builder newTraitNamed: #TComprehension.
669681
tDefinition := builder newTraitNamed: #TDefinition.
670682
(tDecoratorExpression := builder newTraitNamed: #TDecoratorExpression) comment: 'I represent an entity that *can* be the expression of a decorator.'.
671683
tUnaryOperator := builder newTraitNamed: #TUnaryOperator.
684+
tWithStatementItem := (builder newTraitNamed: #TWithStatementItem) comment: 'I represent an entity that can be the item of a with_statement.'.
672685
tWithElseClause := builder newTraitNamed: #TWithElseClause.
673686

674687
"Remotes"

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `parentWithClauseItem` | `FASTPyTWithStatementItem` | `items` | `FASTPyWithStatement` | |
9+
10+
### Children
11+
| Relation | Origin | Opposite | Type | Comment |
12+
|---|
13+
| `source` | `FASTPyAsPattern` | `parentAsPatternSource` | `FASTPyTAsPatternSource` | |
14+
| `target` | `FASTPyAsPattern` | `parentAsPatternTarget` | `FASTPyTAsPatternTarget` | |
15+
16+
17+
18+
"
119
Class {
220
#name : 'FASTPyAsPattern',
321
#superclass : 'FASTPyEntity',
22+
#traits : 'FASTPyTWithStatementItem',
23+
#classTraits : 'FASTPyTWithStatementItem classTrait',
24+
#instVars : [
25+
'#source => FMOne type: #FASTPyTAsPatternSource opposite: #parentAsPatternSource',
26+
'#target => FMOne type: #FASTPyTAsPatternTarget opposite: #parentAsPatternTarget'
27+
],
428
#category : 'FAST-Python-Model-Entities',
529
#package : 'FAST-Python-Model',
630
#tag : 'Entities'
@@ -14,3 +38,47 @@ FASTPyAsPattern class >> annotation [
1438
<generated>
1539
^ self
1640
]
41+
42+
{ #category : 'accessing' }
43+
FASTPyAsPattern >> source [
44+
"Relation named: #source type: #FASTPyTAsPatternSource opposite: #parentAsPatternSource"
45+
46+
<generated>
47+
^ source
48+
]
49+
50+
{ #category : 'accessing' }
51+
FASTPyAsPattern >> source: anObject [
52+
53+
<generated>
54+
source := anObject
55+
]
56+
57+
{ #category : 'navigation' }
58+
FASTPyAsPattern >> sourceGroup [
59+
<generated>
60+
<navigation: 'Source'>
61+
^ MooseSpecializedGroup with: self source
62+
]
63+
64+
{ #category : 'accessing' }
65+
FASTPyAsPattern >> target [
66+
"Relation named: #target type: #FASTPyTAsPatternTarget opposite: #parentAsPatternTarget"
67+
68+
<generated>
69+
^ target
70+
]
71+
72+
{ #category : 'accessing' }
73+
FASTPyAsPattern >> target: anObject [
74+
75+
<generated>
76+
target := anObject
77+
]
78+
79+
{ #category : 'navigation' }
80+
FASTPyAsPattern >> targetGroup [
81+
<generated>
82+
<navigation: 'Target'>
83+
^ MooseSpecializedGroup with: self target
84+
]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| `expressionStatementOwner` | `FASTTExpression` | `expression` | `FASTTExpressionStatement` | The expression statement that own me (if it's the case|
1111
| `pairKeyOwner` | `FASTTExpression` | `key` | `FASTPyPair` | |
1212
| `pairValueOwner` | `FASTTExpression` | `value` | `FASTPyPair` | |
13+
| `parentAsPatternSource` | `FASTPyTAsPatternSource` | `source` | `FASTPyAsPattern` | |
1314
| `parentConditional` | `FASTTExpression` | `condition` | `FASTTWithCondition` | Optional condition statement/expression where this expression is used|
1415
| `parentDeclarator` | `FASTPyTDecoratorExpression` | `expression` | `FASTPyDecorator` | |
1516
| `parentExpression` | `FASTTExpression` | `expression` | `FASTTUnaryExpression` | Parent (unary) expression|
@@ -38,8 +39,8 @@
3839
Class {
3940
#name : 'FASTPyCall',
4041
#superclass : 'FASTPyExpression',
41-
#traits : 'FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression + FASTTInvocation',
42-
#classTraits : 'FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait + FASTTInvocation classTrait',
42+
#traits : 'FASTPyTAsPatternSource + FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression + FASTTInvocation',
43+
#classTraits : 'FASTPyTAsPatternSource classTrait + FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait + FASTTInvocation classTrait',
4344
#instVars : [
4445
'#callee => FMOne type: #FASTPyExpression opposite: #caller'
4546
],

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Parents
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
8+
| `parentAsPatternTarget` | `FASTPyTAsPatternTarget` | `target` | `FASTPyAsPattern` | |
89
| `parentDeclarator` | `FASTPyTDecoratorExpression` | `expression` | `FASTPyDecorator` | |
910
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
1011
@@ -14,8 +15,8 @@
1415
Class {
1516
#name : 'FASTPyIdentifier',
1617
#superclass : 'FASTPyExpression',
17-
#traits : 'FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
18-
#classTraits : 'FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
18+
#traits : 'FASTPyTAsPatternTarget + FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
19+
#classTraits : 'FASTPyTAsPatternTarget classTrait + FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
1920
#category : 'FAST-Python-Model-Entities',
2021
#package : 'FAST-Python-Model',
2122
#tag : 'Entities'
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"
2+
I represent an entity that could be aliased in an as pattern.
3+
4+
## Relations
5+
======================
6+
7+
### Parents
8+
| Relation | Origin | Opposite | Type | Comment |
9+
|---|
10+
| `parentAsPatternSource` | `FASTPyTAsPatternSource` | `source` | `FASTPyAsPattern` | |
11+
12+
13+
14+
"
15+
Trait {
16+
#name : 'FASTPyTAsPatternSource',
17+
#instVars : [
18+
'#parentAsPatternSource => FMOne type: #FASTPyAsPattern opposite: #source'
19+
],
20+
#category : 'FAST-Python-Model-Traits',
21+
#package : 'FAST-Python-Model',
22+
#tag : 'Traits'
23+
}
24+
25+
{ #category : 'meta' }
26+
FASTPyTAsPatternSource classSide >> annotation [
27+
28+
<FMClass: #TAsPatternSource super: #Object>
29+
<package: #'FAST-Python-Model'>
30+
<generated>
31+
^ self
32+
]
33+
34+
{ #category : 'accessing' }
35+
FASTPyTAsPatternSource >> parentAsPatternSource [
36+
"Relation named: #parentAsPatternSource type: #FASTPyAsPattern opposite: #source"
37+
38+
<generated>
39+
<container>
40+
<derived>
41+
^ parentAsPatternSource
42+
]
43+
44+
{ #category : 'accessing' }
45+
FASTPyTAsPatternSource >> parentAsPatternSource: anObject [
46+
47+
<generated>
48+
parentAsPatternSource := anObject
49+
]
50+
51+
{ #category : 'navigation' }
52+
FASTPyTAsPatternSource >> parentAsPatternSourceGroup [
53+
<generated>
54+
<navigation: 'ParentAsPatternSource'>
55+
^ MooseSpecializedGroup with: self parentAsPatternSource
56+
]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"
2+
I represent an entity that could be the alias/target of an as pattern.
3+
4+
## Relations
5+
======================
6+
7+
### Parents
8+
| Relation | Origin | Opposite | Type | Comment |
9+
|---|
10+
| `parentAsPatternTarget` | `FASTPyTAsPatternTarget` | `target` | `FASTPyAsPattern` | |
11+
12+
13+
14+
"
15+
Trait {
16+
#name : 'FASTPyTAsPatternTarget',
17+
#instVars : [
18+
'#parentAsPatternTarget => FMOne type: #FASTPyAsPattern opposite: #target'
19+
],
20+
#category : 'FAST-Python-Model-Traits',
21+
#package : 'FAST-Python-Model',
22+
#tag : 'Traits'
23+
}
24+
25+
{ #category : 'meta' }
26+
FASTPyTAsPatternTarget classSide >> annotation [
27+
28+
<FMClass: #TAsPatternTarget super: #Object>
29+
<package: #'FAST-Python-Model'>
30+
<generated>
31+
^ self
32+
]
33+
34+
{ #category : 'accessing' }
35+
FASTPyTAsPatternTarget >> parentAsPatternTarget [
36+
"Relation named: #parentAsPatternTarget type: #FASTPyAsPattern opposite: #target"
37+
38+
<generated>
39+
<container>
40+
<derived>
41+
^ parentAsPatternTarget
42+
]
43+
44+
{ #category : 'accessing' }
45+
FASTPyTAsPatternTarget >> parentAsPatternTarget: anObject [
46+
47+
<generated>
48+
parentAsPatternTarget := anObject
49+
]
50+
51+
{ #category : 'navigation' }
52+
FASTPyTAsPatternTarget >> parentAsPatternTargetGroup [
53+
<generated>
54+
<navigation: 'ParentAsPatternTarget'>
55+
^ MooseSpecializedGroup with: self parentAsPatternTarget
56+
]

‎src/FAST-Python-Model/FASTPyTEntityCreator.trait.st‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -839,20 +839,6 @@ FASTPyTEntityCreator >> newWhileStatement [
839839
^ self add: FASTPyWhileStatement new
840840
]
841841

842-
{ #category : 'entity creation' }
843-
FASTPyTEntityCreator >> newWithClause [
844-
845-
<generated>
846-
^ self add: FASTPyWithClause new
847-
]
848-
849-
{ #category : 'entity creation' }
850-
FASTPyTEntityCreator >> newWithItem [
851-
852-
<generated>
853-
^ self add: FASTPyWithItem new
854-
]
855-
856842
{ #category : 'entity creation' }
857843
FASTPyTEntityCreator >> newWithStatement [
858844

0 commit comments

Comments
 (0)