Skip to content

Commit 5714923

Browse files
committed
Basic Lambda management
1 parent 787ce49 commit 5714923

5 files changed

Lines changed: 111 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ Class {
150150
'tWithStatements',
151151
'tNumericalLiteral',
152152
'tComprehension',
153-
'tWithCondition'
153+
'tWithCondition',
154+
'tWithParameters'
154155
],
155156
#category : 'FAST-Python-Model-Generator',
156157
#package : 'FAST-Python-Model-Generator'
@@ -406,6 +407,9 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
406407
keywordArgument --|> expression.
407408
keywordArgument --|> tNamedEntity.
408409

410+
lambda --|> expression.
411+
lambda --|> tWithParameters.
412+
409413
list --|> collectionInitializer.
410414

411415
listComprehension --|> expression.
@@ -562,6 +566,8 @@ FASTPythonMetamodelGenerator >> defineRelations [
562566

563567
((keywordArgument property: #value) comment: 'The value of the keyword argument.')
564568
<>- ((expression property: #keywordArgumentOwner) comment: 'Keyword argument from which I am the value (if it''s the case)').
569+
570+
(lambda property: #expression) <>- (expression property: #lambdaOwner).
565571

566572
((listSplat property: #iterable) comment: 'The iterable to unpack. Can be a collection, a call, an attribute access or a subscript.')
567573
<>- ((expression property: #listSplatOwner) comment: 'List splat unpacking me (if it''s the case)').
@@ -625,5 +631,6 @@ FASTPythonMetamodelGenerator >> defineTraits [
625631
tStringLiteral := self remoteTrait: #TStringLiteral withPrefix: #FAST.
626632
tVariableEntity := self remoteTrait: #TVariableEntity withPrefix: #FAST.
627633
tWithCondition := self remoteTrait: #TWithCondition withPrefix: #FAST.
634+
tWithParameters := self remoteTrait: #TWithParameters withPrefix: #FAST.
628635
tWithStatements := self remoteTrait: #TWithStatements withPrefix: #FAST
629636
]

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| `forStatementRightOwner` | `FASTPyExpression` | `left` | `FASTPyForStatement` | The for statement owner (if possible)|
2525
| `ifClauseOwner` | `FASTPyExpression` | `expression` | `FASTPyIfClause` | |
2626
| `keywordArgumentOwner` | `FASTPyExpression` | `value` | `FASTPyKeywordArgument` | Keyword argument from which I am the value (if it's the case)|
27+
| `lambdaOwner` | `FASTPyExpression` | `expression` | `FASTPyLambda` | |
2728
| `listSplatOwner` | `FASTPyExpression` | `iterable` | `FASTPyListSplat` | List splat unpacking me (if it's the case)|
2829
| `pairKeyOwner` | `FASTTExpression` | `key` | `FASTPyPair` | |
2930
| `pairValueOwner` | `FASTTExpression` | `value` | `FASTPyPair` | |
@@ -72,6 +73,7 @@ Class {
7273
'#forStatementRightOwner => FMOne type: #FASTPyForStatement opposite: #left',
7374
'#ifClauseOwner => FMOne type: #FASTPyIfClause opposite: #expression',
7475
'#keywordArgumentOwner => FMOne type: #FASTPyKeywordArgument opposite: #value',
76+
'#lambdaOwner => FMOne type: #FASTPyLambda opposite: #expression',
7577
'#listSplatOwner => FMOne type: #FASTPyListSplat opposite: #iterable',
7678
'#parentComparisonOperator => FMOne type: #FASTPyComparisonOperator opposite: #operands',
7779
'#parentUnaryOperator => FMOne type: #FASTPyTUnaryOperator opposite: #argument',
@@ -484,6 +486,30 @@ FASTPyExpression >> keywordArgumentOwnerGroup [
484486
^ MooseSpecializedGroup with: self keywordArgumentOwner
485487
]
486488

489+
{ #category : 'accessing' }
490+
FASTPyExpression >> lambdaOwner [
491+
"Relation named: #lambdaOwner type: #FASTPyLambda opposite: #expression"
492+
493+
<generated>
494+
<container>
495+
<derived>
496+
^ lambdaOwner
497+
]
498+
499+
{ #category : 'accessing' }
500+
FASTPyExpression >> lambdaOwner: anObject [
501+
502+
<generated>
503+
lambdaOwner := anObject
504+
]
505+
506+
{ #category : 'navigation' }
507+
FASTPyExpression >> lambdaOwnerGroup [
508+
<generated>
509+
<navigation: 'LambdaOwner'>
510+
^ MooseSpecializedGroup with: self lambdaOwner
511+
]
512+
487513
{ #category : 'accessing' }
488514
FASTPyExpression >> listSplatOwner [
489515
"Relation named: #listSplatOwner type: #FASTPyListSplat opposite: #iterable"
Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1+
"
2+
## Relations
3+
======================
4+
5+
### Children
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `expression` | `FASTPyLambda` | `lambdaOwner` | `FASTPyExpression` | |
9+
| `parameters` | `FASTTWithParameters` | `parameterOwner` | `FASTTVariableEntity` | My parameters|
10+
11+
12+
13+
"
114
Class {
215
#name : 'FASTPyLambda',
3-
#superclass : 'FASTPyEntity',
16+
#superclass : 'FASTPyExpression',
17+
#traits : 'FASTTWithParameters',
18+
#classTraits : 'FASTTWithParameters classTrait',
19+
#instVars : [
20+
'#expression => FMOne type: #FASTPyExpression opposite: #lambdaOwner'
21+
],
422
#category : 'FAST-Python-Model-Entities',
523
#package : 'FAST-Python-Model',
624
#tag : 'Entities'
@@ -9,8 +27,30 @@ Class {
927
{ #category : 'meta' }
1028
FASTPyLambda class >> annotation [
1129

12-
<FMClass: #Lambda super: #FASTPyEntity>
30+
<FMClass: #Lambda super: #FASTPyExpression>
1331
<package: #'FAST-Python-Model'>
1432
<generated>
1533
^ self
1634
]
35+
36+
{ #category : 'accessing' }
37+
FASTPyLambda >> expression [
38+
"Relation named: #expression type: #FASTPyExpression opposite: #lambdaOwner"
39+
40+
<generated>
41+
^ expression
42+
]
43+
44+
{ #category : 'accessing' }
45+
FASTPyLambda >> expression: anObject [
46+
47+
<generated>
48+
expression := anObject
49+
]
50+
51+
{ #category : 'navigation' }
52+
FASTPyLambda >> expressionGroup [
53+
<generated>
54+
<navigation: 'Expression'>
55+
^ MooseSpecializedGroup with: self expression
56+
]

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,33 @@ FASTPythonImporterTest >> testInteger [
35993599
self assert: (boolean isOfType: FASTTLiteral)
36003600
]
36013601

3602+
{ #category : 'tests - lambdas' }
3603+
FASTPythonImporterTest >> testLambda [
3604+
<generated>
3605+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
3606+
Regenerate executing: self regenerateTest: #testLambda "
3607+
3608+
self parse: 'lambda : 3'.
3609+
3610+
self assert: (fast allWithType: FASTPyInteger) size equals: 1.
3611+
self assert: (fast allWithType: FASTPyLambda) size equals: 1.
3612+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
3613+
3614+
stack push: fast rootEntities anyOne containedEntities first.
3615+
self assert: self topEntity sourceCode equals: 'lambda : 3'.
3616+
self assert: (self topEntity isOfType: FASTPyLambda).
3617+
self assert: (self topEntity isOfType: FASTTWithParameters).
3618+
3619+
"Testing value of monovalue relation expression"
3620+
self assert: self topEntity expression isNotNil.
3621+
3622+
stack push: self topEntity expression.
3623+
self assert: self topEntity sourceCode equals: '3'.
3624+
self assert: (self topEntity isOfType: FASTPyInteger).
3625+
self assert: (self topEntity isOfType: FASTTLiteral).
3626+
self assert: (self topEntity isOfType: FASTTNumericalLiteral)
3627+
]
3628+
36023629
{ #category : 'tests - collections' }
36033630
FASTPythonImporterTest >> testList [
36043631
<generated>

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,14 @@ TSFASTPythonImporter >> visitInteger: aTSNode [
368368
ifFalse: [ FASTPyInteger ])
369369
]
370370

371+
{ #category : 'visiting' }
372+
TSFASTPythonImporter >> visitLambda: aTSNode [
373+
374+
self onNextContextDo: [ :entry | entry add: 'expression' asAliasOfField: 'body' ].
375+
376+
^ self createEntityForNode: aTSNode kind: FASTPyLambda
377+
]
378+
371379
{ #category : 'visiting' }
372380
TSFASTPythonImporter >> visitLineContinuation: aTSNode [
373381
"We do not represent that in FAST, at least for the moment. So I skip this node and act as if the children were in my parent."

0 commit comments

Comments
 (0)