Skip to content

Commit 6c78a19

Browse files
committed
Mostly handle yield statement
1 parent 16cb5d1 commit 6c78a19

File tree

5 files changed

+143
-4
lines changed

5 files changed

+143
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,9 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
582582
whileStatement --|> tWithElseClause.
583583

584584
withStatement --|> statement.
585-
withStatement --|> tStatementBlock
585+
withStatement --|> tStatementBlock.
586+
587+
yield --|> expression
586588
]
587589

588590
{ #category : 'definition' }
@@ -781,7 +783,9 @@ FASTPythonMetamodelGenerator >> defineRelations [
781783

782784
(unionType property: #types) <>-* (type property: #parentUnionType).
783785

784-
(withStatement property: #items) <>-* (tWithStatementItem property: #parentWithStatementItem)
786+
(withStatement property: #items) <>-* (tWithStatementItem property: #parentWithStatementItem).
787+
788+
(yield property: #expression) <>- (expression property: #parentYield)
785789
]
786790

787791
{ #category : 'definition' }

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
| `parentType` | `FASTPyTTypeContent` | `content` | `FASTPyType` | |
4444
| `parentUnaryOperator` | `FASTPyExpression` | `argument` | `FASTPyTUnaryOperator` | Parent unary operator in which I am.|
4545
| `parentWalrus` | `FASTPyExpression` | `value` | `FASTPyWalrus` | |
46+
| `parentYield` | `FASTPyExpression` | `expression` | `FASTPyYield` | |
4647
| `prarentPrintStatement` | `FASTPyExpression` | `expressions` | `FASTPyPrintStatement` | |
4748
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
4849
@@ -91,6 +92,7 @@ Class {
9192
'#parentSubscriptValue => FMOne type: #FASTPySubscript opposite: #value',
9293
'#parentUnaryOperator => FMOne type: #FASTPyTUnaryOperator opposite: #argument',
9394
'#parentWalrus => FMOne type: #FASTPyWalrus opposite: #value',
95+
'#parentYield => FMOne type: #FASTPyYield opposite: #expression',
9496
'#prarentPrintStatement => FMOne type: #FASTPyPrintStatement opposite: #expressions'
9597
],
9698
#category : 'FAST-Python-Model-Entities',
@@ -805,6 +807,30 @@ FASTPyExpression >> parentWalrusGroup [
805807
^ MooseSpecializedGroup with: self parentWalrus
806808
]
807809

810+
{ #category : 'accessing' }
811+
FASTPyExpression >> parentYield [
812+
"Relation named: #parentYield type: #FASTPyYield opposite: #expression"
813+
814+
<generated>
815+
<container>
816+
<derived>
817+
^ parentYield
818+
]
819+
820+
{ #category : 'accessing' }
821+
FASTPyExpression >> parentYield: anObject [
822+
823+
<generated>
824+
parentYield := anObject
825+
]
826+
827+
{ #category : 'navigation' }
828+
FASTPyExpression >> parentYieldGroup [
829+
<generated>
830+
<navigation: 'ParentYield'>
831+
^ MooseSpecializedGroup with: self parentYield
832+
]
833+
808834
{ #category : 'accessing' }
809835
FASTPyExpression >> prarentPrintStatement [
810836
"Relation named: #prarentPrintStatement type: #FASTPyPrintStatement opposite: #expressions"
Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Children
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `expression` | `FASTPyYield` | `parentYield` | `FASTPyExpression` | |
9+
10+
11+
12+
"
113
Class {
214
#name : 'FASTPyYield',
3-
#superclass : 'FASTPyEntity',
15+
#superclass : 'FASTPyExpression',
16+
#instVars : [
17+
'#expression => FMOne type: #FASTPyExpression opposite: #parentYield'
18+
],
419
#category : 'FAST-Python-Model-Entities',
520
#package : 'FAST-Python-Model',
621
#tag : 'Entities'
@@ -9,8 +24,30 @@ Class {
924
{ #category : 'meta' }
1025
FASTPyYield class >> annotation [
1126

12-
<FMClass: #Yield super: #FASTPyEntity>
27+
<FMClass: #Yield super: #FASTPyExpression>
1328
<package: #'FAST-Python-Model'>
1429
<generated>
1530
^ self
1631
]
32+
33+
{ #category : 'accessing' }
34+
FASTPyYield >> expression [
35+
"Relation named: #expression type: #FASTPyExpression opposite: #parentYield"
36+
37+
<generated>
38+
^ expression
39+
]
40+
41+
{ #category : 'accessing' }
42+
FASTPyYield >> expression: anObject [
43+
44+
<generated>
45+
expression := anObject
46+
]
47+
48+
{ #category : 'navigation' }
49+
FASTPyYield >> expressionGroup [
50+
<generated>
51+
<navigation: 'Expression'>
52+
^ MooseSpecializedGroup with: self expression
53+
]

src/FAST-Python-Tools-Tests/FASTPythonImporterTest.class.st

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51857,6 +51857,70 @@ FASTPythonImporterTest >> testWithStatementWithMultipleAsPattern [
5185751857
self assert: (self topEntity isOfType: FASTPyPassStatement)
5185851858
]
5185951859

51860+
{ #category : 'tests' }
51861+
FASTPythonImporterTest >> testYield [
51862+
<generated>
51863+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
51864+
Regenerate executing: self regenerateTest: #testYield "
51865+
51866+
self parse: 'yield'.
51867+
51868+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
51869+
self assert: (fast allWithType: FASTPyYield) size equals: 1.
51870+
51871+
stack push: fast rootEntities anyOne containedEntities first.
51872+
self assert: self topEntity sourceCode equals: 'yield'.
51873+
self assert: (self topEntity isOfType: FASTPyYield)
51874+
]
51875+
51876+
{ #category : 'tests' }
51877+
FASTPythonImporterTest >> testYieldFrom [
51878+
<generated>
51879+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
51880+
Regenerate executing: self regenerateTest: #testYieldFrom "
51881+
51882+
self parse: 'yield from x'.
51883+
51884+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 1.
51885+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
51886+
self assert: (fast allWithType: FASTPyYield) size equals: 1.
51887+
51888+
stack push: fast rootEntities anyOne containedEntities first.
51889+
self assert: self topEntity sourceCode equals: 'yield from x'.
51890+
self assert: (self topEntity isOfType: FASTPyYield).
51891+
51892+
"Testing value of monovalue relation expression"
51893+
self assert: self topEntity expression isNotNil.
51894+
51895+
stack push: self topEntity expression.
51896+
self assert: self topEntity sourceCode equals: 'x'.
51897+
self assert: (self topEntity isOfType: FASTPyIdentifier)
51898+
]
51899+
51900+
{ #category : 'tests' }
51901+
FASTPythonImporterTest >> testYieldWithIdentifier [
51902+
<generated>
51903+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
51904+
Regenerate executing: self regenerateTest: #testYieldWithIdentifier "
51905+
51906+
self parse: 'yield x'.
51907+
51908+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 1.
51909+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
51910+
self assert: (fast allWithType: FASTPyYield) size equals: 1.
51911+
51912+
stack push: fast rootEntities anyOne containedEntities first.
51913+
self assert: self topEntity sourceCode equals: 'yield x'.
51914+
self assert: (self topEntity isOfType: FASTPyYield).
51915+
51916+
"Testing value of monovalue relation expression"
51917+
self assert: self topEntity expression isNotNil.
51918+
51919+
stack push: self topEntity expression.
51920+
self assert: self topEntity sourceCode equals: 'x'.
51921+
self assert: (self topEntity isOfType: FASTPyIdentifier)
51922+
]
51923+
5186051924
{ #category : 'running' }
5186151925
FASTPythonImporterTest >> topEntity [
5186251926

src/FAST-Python-Tools/TSFASTPythonImporter.class.st

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,3 +1065,11 @@ TSFASTPythonImporter >> visitWithStatement: aTSNode [
10651065

10661066
^ self handleNode: aTSNode kind: FASTPyWithStatement
10671067
]
1068+
1069+
{ #category : 'visiting - alias' }
1070+
TSFASTPythonImporter >> visitYield: aNode [
1071+
1072+
self onNextContextDo: [ :entry | entry aliasUnnamedFieldAs: #expression ].
1073+
1074+
^ self handleNode: aNode kind: FASTPyYield
1075+
]

0 commit comments

Comments
 (0)