Skip to content

Commit 9c6d320

Browse files
committed
Manage dictionary splat parameters
1 parent 245c4d8 commit 9c6d320

5 files changed

Lines changed: 74 additions & 11 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Class {
3636
'dictionary',
3737
'dictionaryComprehension',
3838
'dictionarySplat',
39-
'dictionarySplatPattern',
4039
'dottedName',
4140
'elifClause',
4241
'ellipsis',
@@ -161,7 +160,8 @@ Class {
161160
'tSplatExpression',
162161
'listSplatParameter',
163162
'tSplatParameterTarget',
164-
'tSplatParameter'
163+
'tSplatParameter',
164+
'dictionarySplatParameter'
165165
],
166166
#category : 'FAST-Python-Model-Generator',
167167
#package : 'FAST-Python-Model-Generator'
@@ -225,7 +225,7 @@ FASTPythonMetamodelGenerator >> defineClasses [
225225
dictionary := builder ensureClassNamed: #Dictionary."To Review"
226226
dictionaryComprehension := builder ensureClassNamed: #DictionaryComprehension."Todo"
227227
dictionarySplat := builder ensureClassNamed: #DictionarySplat."Todo"
228-
dictionarySplatPattern := builder ensureClassNamed: #DictionarySplatPattern."Todo"
228+
dictionarySplatParameter := builder ensureClassNamed: #DictionarySplatParameter."Todo"
229229
dottedName := builder ensureClassNamed: #DottedName."Todo"
230230
elifClause := builder ensureClassNamed: #ElifClause."Todo"
231231
ellipsis := builder ensureClassNamed: #Ellipsis.
@@ -390,8 +390,8 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
390390

391391
dictionarySplat --|> collectionSplat.
392392

393-
dictionarySplatPattern --|> parameter.
394-
dictionarySplatPattern --|> tSplatParameter.
393+
dictionarySplatParameter --|> parameter.
394+
dictionarySplatParameter --|> tSplatParameter.
395395

396396
elseClause --|> block.
397397

src/FAST-Python-Model/FASTPyDictionarySplatPattern.class.st renamed to src/FAST-Python-Model/FASTPyDictionarySplatParameter.class.st

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
"
1313
Class {
14-
#name : 'FASTPyDictionarySplatPattern',
14+
#name : 'FASTPyDictionarySplatParameter',
1515
#superclass : 'FASTPyParameter',
1616
#traits : 'FASTPyTSplatParameter',
1717
#classTraits : 'FASTPyTSplatParameter classTrait',
@@ -21,9 +21,9 @@ Class {
2121
}
2222

2323
{ #category : 'meta' }
24-
FASTPyDictionarySplatPattern class >> annotation [
24+
FASTPyDictionarySplatParameter class >> annotation [
2525

26-
<FMClass: #DictionarySplatPattern super: #FASTPyParameter>
26+
<FMClass: #DictionarySplatParameter super: #FASTPyParameter>
2727
<package: #'FAST-Python-Model'>
2828
<generated>
2929
^ self

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,10 @@ FASTPyTEntityCreator >> newDictionarySplat [
259259
]
260260

261261
{ #category : 'entity creation' }
262-
FASTPyTEntityCreator >> newDictionarySplatPattern [
262+
FASTPyTEntityCreator >> newDictionarySplatParameter [
263263

264264
<generated>
265-
^ self add: FASTPyDictionarySplatPattern new
265+
^ self add: FASTPyDictionarySplatParameter new
266266
]
267267

268268
{ #category : 'entity creation' }

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,6 +3965,54 @@ FASTPythonImporterTest >> testDictionarySplatOnSubscript [
39653965
self assert: (self topEntity isOfType: FASTPyIdentifier)
39663966
]
39673967

3968+
{ #category : 'tests - function definitions' }
3969+
FASTPythonImporterTest >> testDictionarySplatParameter [
3970+
<generated>
3971+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
3972+
Regenerate executing: self regenerateTest: #testDictionarySplatParameter "
3973+
3974+
self parse: 'def function(**kwargs): pass'.
3975+
3976+
self assert: (fast allWithType: FASTPyBlock) size equals: 1.
3977+
self assert: (fast allWithType: FASTPyDictionarySplatParameter) size equals: 1.
3978+
self assert: (fast allWithType: FASTPyFunctionDefinition) size equals: 1.
3979+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
3980+
self assert: (fast allWithType: FASTPyPassStatement) size equals: 1.
3981+
3982+
stack push: fast rootEntities anyOne containedEntities first.
3983+
self assert: self topEntity sourceCode equals: 'def function(**kwargs): pass'.
3984+
self assert: (self topEntity isOfType: FASTPyFunctionDefinition).
3985+
self assert: (self topEntity isOfType: FASTPyTDefinition).
3986+
self assert: (self topEntity isOfType: FASTTWithParameters).
3987+
self assert: (self topEntity isOfType: FASTTWithStatements).
3988+
self assert: self topEntity name equals: 'function'.
3989+
3990+
"Testing value of multivalued relation parameters"
3991+
self assert: self topEntity parameters size equals: 1.
3992+
3993+
stack push: (stack top parameters at: 1).
3994+
self assert: self topEntity sourceCode equals: '**kwargs'.
3995+
self assert: (self topEntity isOfType: FASTPyDictionarySplatParameter).
3996+
self assert: (self topEntity isOfType: FASTTVariableEntity).
3997+
self assert: self topEntity name equals: 'kwargs'.
3998+
stack pop.
3999+
4000+
"Testing value of monovalue relation statementBlock"
4001+
self assert: self topEntity statementBlock isNotNil.
4002+
4003+
stack push: self topEntity statementBlock.
4004+
self assert: self topEntity sourceCode equals: 'pass'.
4005+
self assert: (self topEntity isOfType: FASTPyBlock).
4006+
self assert: (self topEntity isOfType: FASTTStatementBlock).
4007+
4008+
"Testing value of multivalued relation statements"
4009+
self assert: self topEntity statements size equals: 1.
4010+
4011+
stack push: (stack top statements at: 1).
4012+
self assert: self topEntity sourceCode equals: 'pass'.
4013+
self assert: (self topEntity isOfType: FASTPyPassStatement)
4014+
]
4015+
39684016
{ #category : 'tests - literals' }
39694017
FASTPythonImporterTest >> testDoubleQuotedString [
39704018

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ TSFASTPythonImporter >> visitDictionarySplat: aTSNode [
254254
^ self handleNode: aTSNode kind: FASTPyDictionarySplat
255255
]
256256

257+
{ #category : 'visiting - alias' }
258+
TSFASTPythonImporter >> visitDictionarySplatPattern: aTSNode [
259+
"In case we are a parameter we skip the children because it always is an identifier"
260+
261+
(#( parameters lambda_parameters ) includes: aTSNode parent type) ifTrue: [
262+
| fastEntity |
263+
fastEntity := self instantiateFastEntity: FASTPyDictionarySplatParameter from: aTSNode.
264+
self topFastEntity addParameter: fastEntity.
265+
fastEntity name: (self sourceCodeOf: aTSNode collectNamedChild anyOne).
266+
^ fastEntity ].
267+
268+
^ self handleNode: aTSNode
269+
]
270+
257271
{ #category : 'visiting' }
258272
TSFASTPythonImporter >> visitDottedName: aTSNode [
259273

@@ -383,7 +397,8 @@ TSFASTPythonImporter >> visitIdentifier: aNode [
383397
(#( parameters lambda_parameters ) includes: aNode parent type) ifTrue: [
384398
| parameter |
385399
parameter := self handleNode: aNode kind: FASTPyParameter parentBlock: [ :entity | self topFastEntity addParameter: entity ].
386-
parameter name: parameter sourceCode ].
400+
parameter name: parameter sourceCode.
401+
^ parameter ].
387402

388403
"If we are in a field `name` then we are probably in a definition of an entity and we set my content as a name."
389404
(context anySatisfy: [ :entry |

0 commit comments

Comments
 (0)