Skip to content

Commit ab1d684

Browse files
committed
It's crazy but for statement can have an else clause
1 parent 9c7f577 commit ab1d684

6 files changed

Lines changed: 219 additions & 46 deletions

File tree

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ Class {
152152
'tWithCondition',
153153
'tWithParameters',
154154
'tDefinition',
155-
'tDecoratorExpression'
155+
'tDecoratorExpression',
156+
'tWithElseClause'
156157
],
157158
#category : 'FAST-Python-Model-Generator',
158159
#package : 'FAST-Python-Model-Generator'
@@ -384,6 +385,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
384385

385386
forStatement --|> statement.
386387
forStatement --|> tLoopStatement.
388+
forStatement --|> tWithElseClause.
387389

388390
functionDefinition --|> tNamedBehaviouralEntity.
389391
functionDefinition --|> tDefinition.
@@ -400,6 +402,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
400402

401403
ifStatement --|> statement.
402404
ifStatement --|> tConditionalStatement.
405+
ifStatement --|> tWithElseClause.
403406

404407
importStatement --|> import.
405408

@@ -525,7 +528,7 @@ FASTPythonMetamodelGenerator >> defineRelations [
525528

526529
((assertStatement property: #expression) comment: 'The expression asserted')
527530
<>- ((expression property: #assertOwner) comment: 'The assert statement that own the expression (if it''s the case)').
528-
531+
529532
(await property: #expression) <>- (expression property: #parentAwait).
530533

531534
((call property: #callee) comment:
@@ -538,11 +541,11 @@ FASTPythonMetamodelGenerator >> defineRelations [
538541
((comparisonOperator property: #operands) comment:
539542
'List of the operands of the comparison operands. For example if we have `a == b != c`, it will be a, b and c.')
540543
<>-* ((expression property: #parentComparisonOperator) comment: 'Parent comparison expression of which I am.').
541-
544+
542545
(conditionalExpression property: #thenExpression) <>- (expression property: #conditionalExpressionThenOwner).
543-
546+
544547
(conditionalExpression property: #elseExpression) <>- (expression property: #conditionalExpressionElseOwner).
545-
548+
546549
(decorator property: #expression) <>- (tDecoratorExpression property: #parentDeclarator).
547550

548551
((deleteStatement property: #expression) comment: 'The expression to apply the delete on')
@@ -561,13 +564,11 @@ FASTPythonMetamodelGenerator >> defineRelations [
561564

562565
((globalStatement property: #variables) comment: 'The variables scoped')
563566
<>-* ((variable property: #globalOwner) comment: 'The global statement defining my scope (if it''s the case)').
564-
567+
565568
(ifClause property: #expression) <>- (expression property: #ifClauseOwner).
566569

567570
(ifStatement property: #thenClause) <>- (thenClause property: #ifStatementOwner).
568571

569-
(ifStatement property: #elseClause) <>- (elseClause property: #ifStatementOwner).
570-
571572
(ifStatement property: #elifClauses) <>-* (elifClause property: #ifStatementOwner).
572573

573574
((import property: #importedEntities) comment: 'List of the imported entities.')
@@ -576,12 +577,12 @@ FASTPythonMetamodelGenerator >> defineRelations [
576577
((importFromStatement property: #fromModule) comment:
577578
'Module in which the imported entities should be looked for. `from datetime import date` has `datetime` as fromModule..')
578579
<>- ((fromModule property: #import) comment: 'Import declaring me as from import module.').
579-
580+
580581
(interpolation property: #expression) <>- (expression property: #parentInterpolation).
581582

582583
((keywordArgument property: #value) comment: 'The value of the keyword argument.')
583584
<>- ((expression property: #keywordArgumentOwner) comment: 'Keyword argument from which I am the value (if it''s the case)').
584-
585+
585586
(lambda property: #expression) <>- (expression property: #lambdaOwner).
586587

587588
((listSplat property: #iterable) comment: 'The iterable to unpack. Can be a collection, a call, an attribute access or a subscript.')
@@ -593,12 +594,12 @@ FASTPythonMetamodelGenerator >> defineRelations [
593594
(pair property: #key) <>- (tExpression property: #pairKeyOwner).
594595

595596
(pair property: #value) <>- (tExpression property: #pairValueOwner).
596-
597+
597598
(patternList property: #elements) <>-* (expression property: #patternListOwner).
598599

599600
((slice property: #components) comment: 'The components are the expressions between the `:` of a slice.')
600601
<>-* ((expression property: #sliceOwner) comment: 'Slice in which I am a component (start, end or step) (If it''s the case)''').
601-
602+
602603
(string property: #interpolations) <>-* (interpolation property: #parentString).
603604

604605
((subscript property: #value) comment: 'The receiver of the subscript')
@@ -610,13 +611,15 @@ FASTPythonMetamodelGenerator >> defineRelations [
610611
(tComprehension property: #body) <>- (expression property: #comprehensionBodyOwner).
611612

612613
(tComprehension property: #clauses) <>-* (expression property: #comprehensionClauseOwner).
613-
614+
614615
(tDefinition property: #decorators) <>-* (decorator property: #definitionOwner).
615-
616+
616617
(tuplePattern property: #patterns) <>-* (expression property: #tuplePatternOwner).
617618

618619
((tUnaryOperator property: #argument) comment: 'Expression influanced by the unary operator..')
619-
<>- ((expression property: #parentUnaryOperator) comment: 'Parent unary operator in which I am.')
620+
<>- ((expression property: #parentUnaryOperator) comment: 'Parent unary operator in which I am.').
621+
622+
(tWithElseClause property: #elseClause) <>- (elseClause property: #ifStatementOwner)
620623
]
621624

622625
{ #category : 'definition' }
@@ -633,6 +636,7 @@ FASTPythonMetamodelGenerator >> defineTraits [
633636
tDecoratorExpression := builder newTraitNamed: #TDecoratorExpression.
634637
tDecoratorExpression comment: 'I represent an entity that *can* be the expression of a decorator.'.
635638
tUnaryOperator := builder newTraitNamed: #TUnaryOperator.
639+
tWithElseClause := builder newTraitNamed: #TWithElseClause.
636640

637641
"Remotes"
638642
tAssignment := self remoteTrait: #TAssignment withPrefix: #FAST.

src/FAST-Python-Model/FASTPyElseClause.class.st

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
### Parents
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
8-
| `ifStatementOwner` | `FASTPyElseClause` | `elseClause` | `FASTPyIfStatement` | |
8+
| `ifStatementOwner` | `FASTPyElseClause` | `elseClause` | `FASTPyTWithElseClause` | |
99
1010
1111
@@ -14,7 +14,7 @@ Class {
1414
#name : 'FASTPyElseClause',
1515
#superclass : 'FASTPyBlock',
1616
#instVars : [
17-
'#ifStatementOwner => FMOne type: #FASTPyIfStatement opposite: #elseClause'
17+
'#ifStatementOwner => FMOne type: #FASTPyTWithElseClause opposite: #elseClause'
1818
],
1919
#category : 'FAST-Python-Model-Entities',
2020
#package : 'FAST-Python-Model',
@@ -32,7 +32,7 @@ FASTPyElseClause class >> annotation [
3232

3333
{ #category : 'accessing' }
3434
FASTPyElseClause >> ifStatementOwner [
35-
"Relation named: #ifStatementOwner type: #FASTPyIfStatement opposite: #elseClause"
35+
"Relation named: #ifStatementOwner type: #FASTPyTWithElseClause opposite: #elseClause"
3636

3737
<generated>
3838
<container>

src/FAST-Python-Model/FASTPyForStatement.class.st

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| Relation | Origin | Opposite | Type | Comment |
1313
|---|
1414
| `body` | `FASTTLoopStatement` | `parentLoopStatement` | `FASTTStatement` | The body of the loop|
15+
| `elseClause` | `FASTPyTWithElseClause` | `ifStatementOwner` | `FASTPyElseClause` | |
1516
| `left` | `FASTPyForStatement` | `forStatementRightOwner` | `FASTPyExpression` | The identifier of the created local variable or tuple|
1617
| `right` | `FASTPyForStatement` | `forStatementLeftOwner` | `FASTPyExpression` | The list that the for statement iterates over|
1718
@@ -28,8 +29,8 @@
2829
Class {
2930
#name : 'FASTPyForStatement',
3031
#superclass : 'FASTPyStatement',
31-
#traits : 'FASTTLoopStatement',
32-
#classTraits : 'FASTTLoopStatement classTrait',
32+
#traits : 'FASTPyTWithElseClause + FASTTLoopStatement',
33+
#classTraits : 'FASTPyTWithElseClause classTrait + FASTTLoopStatement classTrait',
3334
#instVars : [
3435
'#left => FMOne type: #FASTPyExpression opposite: #forStatementRightOwner',
3536
'#right => FMOne type: #FASTPyExpression opposite: #forStatementLeftOwner'

src/FAST-Python-Model/FASTPyIfStatement.class.st

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
|---|
1414
| `condition` | `FASTTWithCondition` | `parentConditional` | `FASTTExpression` | The boolean condition tested|
1515
| `elifClauses` | `FASTPyIfStatement` | `ifStatementOwner` | `FASTPyElifClause` | |
16-
| `elseClause` | `FASTPyIfStatement` | `ifStatementOwner` | `FASTPyElseClause` | |
16+
| `elseClause` | `FASTPyTWithElseClause` | `ifStatementOwner` | `FASTPyElseClause` | |
1717
| `thenClause` | `FASTPyIfStatement` | `ifStatementOwner` | `FASTPyThenClause` | |
1818
1919
@@ -29,11 +29,10 @@
2929
Class {
3030
#name : 'FASTPyIfStatement',
3131
#superclass : 'FASTPyStatement',
32-
#traits : 'FASTTConditionalStatement',
33-
#classTraits : 'FASTTConditionalStatement classTrait',
32+
#traits : 'FASTPyTWithElseClause + FASTTConditionalStatement',
33+
#classTraits : 'FASTPyTWithElseClause classTrait + FASTTConditionalStatement classTrait',
3434
#instVars : [
3535
'#elifClauses => FMMany type: #FASTPyElifClause opposite: #ifStatementOwner',
36-
'#elseClause => FMOne type: #FASTPyElseClause opposite: #ifStatementOwner',
3736
'#thenClause => FMOne type: #FASTPyThenClause opposite: #ifStatementOwner'
3837
],
3938
#category : 'FAST-Python-Model-Entities',
@@ -79,28 +78,6 @@ FASTPyIfStatement >> elifClausesGroup [
7978
^ MooseSpecializedGroup withAll: self elifClauses asSet
8079
]
8180

82-
{ #category : 'accessing' }
83-
FASTPyIfStatement >> elseClause [
84-
"Relation named: #elseClause type: #FASTPyElseClause opposite: #ifStatementOwner"
85-
86-
<generated>
87-
^ elseClause
88-
]
89-
90-
{ #category : 'accessing' }
91-
FASTPyIfStatement >> elseClause: anObject [
92-
93-
<generated>
94-
elseClause := anObject
95-
]
96-
97-
{ #category : 'navigation' }
98-
FASTPyIfStatement >> elseClauseGroup [
99-
<generated>
100-
<navigation: 'ElseClause'>
101-
^ MooseSpecializedGroup with: self elseClause
102-
]
103-
10481
{ #category : 'accessing' }
10582
FASTPyIfStatement >> thenClause [
10683
"Relation named: #thenClause type: #FASTPyThenClause opposite: #ifStatementOwner"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Children
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `elseClause` | `FASTPyTWithElseClause` | `ifStatementOwner` | `FASTPyElseClause` | |
9+
10+
11+
12+
"
13+
Trait {
14+
#name : 'FASTPyTWithElseClause',
15+
#instVars : [
16+
'#elseClause => FMOne type: #FASTPyElseClause opposite: #ifStatementOwner'
17+
],
18+
#category : 'FAST-Python-Model-Traits',
19+
#package : 'FAST-Python-Model',
20+
#tag : 'Traits'
21+
}
22+
23+
{ #category : 'meta' }
24+
FASTPyTWithElseClause classSide >> annotation [
25+
26+
<FMClass: #TWithElseClause super: #Object>
27+
<package: #'FAST-Python-Model'>
28+
<generated>
29+
^ self
30+
]
31+
32+
{ #category : 'accessing' }
33+
FASTPyTWithElseClause >> elseClause [
34+
"Relation named: #elseClause type: #FASTPyElseClause opposite: #ifStatementOwner"
35+
36+
<generated>
37+
^ elseClause
38+
]
39+
40+
{ #category : 'accessing' }
41+
FASTPyTWithElseClause >> elseClause: anObject [
42+
43+
<generated>
44+
elseClause := anObject
45+
]
46+
47+
{ #category : 'navigation' }
48+
FASTPyTWithElseClause >> elseClauseGroup [
49+
<generated>
50+
<navigation: 'ElseClause'>
51+
^ MooseSpecializedGroup with: self elseClause
52+
]

0 commit comments

Comments
 (0)