Skip to content

Commit 71877f6

Browse files
committed
Finish to manage slices children + add new menu to parse 10 batches
1 parent 4c96016 commit 71877f6

File tree

6 files changed

+218
-9
lines changed

6 files changed

+218
-9
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
337337

338338
boolean --|> literal.
339339
boolean --|> tBooleanLiteral.
340+
boolean --|> tSliceContent.
340341

341342
breakStatement --|> statement.
342343

@@ -359,6 +360,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
359360

360361
conditionalExpression --|> expression.
361362
conditionalExpression --|> tWithCondition.
363+
conditionalExpression --|> tSliceContent.
362364

363365
continueStatement --|> statement.
364366

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
| `parentExpressionLeft` | `FASTTExpression` | `leftOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am left side|
1616
| `parentExpressionRight` | `FASTTExpression` | `rightOperand` | `FASTTBinaryExpression` | Parent (binary) expression of which I am right side|
1717
| `returnOwner` | `FASTTExpression` | `expression` | `FASTTReturnStatement` | The return statement that own the expression (if it's the case)|
18+
| `sliceOwner` | `FASTPyTSliceContent` | `components` | `FASTPySlice` | Slice in which I am a component (start, end or step) (If it's the case)'|
1819
1920
2021
## Properties
@@ -30,8 +31,8 @@
3031
Class {
3132
#name : 'FASTPyBoolean',
3233
#superclass : 'FASTPyLiteral',
33-
#traits : 'FASTTBooleanLiteral',
34-
#classTraits : 'FASTTBooleanLiteral classTrait',
34+
#traits : 'FASTPyTSliceContent + FASTTBooleanLiteral',
35+
#classTraits : 'FASTPyTSliceContent classTrait + FASTTBooleanLiteral classTrait',
3536
#category : 'FAST-Python-Model-Entities',
3637
#package : 'FAST-Python-Model',
3738
#tag : 'Entities'

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
## Relations
33
======================
44
5+
### Parents
6+
| Relation | Origin | Opposite | Type | Comment |
7+
|---|
8+
| `sliceOwner` | `FASTPyTSliceContent` | `components` | `FASTPySlice` | Slice in which I am a component (start, end or step) (If it's the case)'|
9+
510
### Children
611
| Relation | Origin | Opposite | Type | Comment |
712
|---|
@@ -15,8 +20,8 @@
1520
Class {
1621
#name : 'FASTPyConditionalExpression',
1722
#superclass : 'FASTPyExpression',
18-
#traits : 'FASTTWithCondition',
19-
#classTraits : 'FASTTWithCondition classTrait',
23+
#traits : 'FASTPyTSliceContent + FASTTWithCondition',
24+
#classTraits : 'FASTPyTSliceContent classTrait + FASTTWithCondition classTrait',
2025
#instVars : [
2126
'#elseExpression => FMOne type: #FASTPyExpression opposite: #conditionalExpressionElseOwner',
2227
'#thenExpression => FMOne type: #FASTPyExpression opposite: #conditionalExpressionThenOwner'

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

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6875,6 +6875,57 @@ FASTPythonImporterTest >> testSliceBinaryOperator [
68756875
self assert: (self topEntity isOfType: FASTPyIdentifier)
68766876
]
68776877

6878+
{ #category : 'tests - subscripts' }
6879+
FASTPythonImporterTest >> testSliceBoolean [
6880+
<generated>
6881+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
6882+
Regenerate executing: self regenerateTest: #testSliceBoolean "
6883+
6884+
self parse: 'lst[True:False]'.
6885+
6886+
self assert: (fast allWithType: FASTPyBoolean) size equals: 2.
6887+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 1.
6888+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
6889+
self assert: (fast allWithType: FASTPySlice) size equals: 1.
6890+
self assert: (fast allWithType: FASTPySubscript) size equals: 1.
6891+
6892+
stack push: fast rootEntities anyOne containedEntities first.
6893+
self assert: self topEntity sourceCode equals: 'lst[True:False]'.
6894+
self assert: (self topEntity isOfType: FASTPySubscript).
6895+
6896+
"Testing value of multivalued relation indices"
6897+
self assert: self topEntity indices size equals: 1.
6898+
6899+
stack push: (stack top indices at: 1).
6900+
self assert: self topEntity sourceCode equals: 'True:False'.
6901+
self assert: (self topEntity isOfType: FASTPySlice).
6902+
6903+
"Testing value of multivalued relation components"
6904+
self assert: self topEntity components size equals: 2.
6905+
6906+
stack push: (stack top components at: 1).
6907+
self assert: self topEntity sourceCode equals: 'True'.
6908+
self assert: (self topEntity isOfType: FASTPyBoolean).
6909+
self assert: (self topEntity isOfType: FASTTBooleanLiteral).
6910+
self assert: (self topEntity isOfType: FASTTLiteral).
6911+
stack pop.
6912+
6913+
stack push: (stack top components at: 2).
6914+
self assert: self topEntity sourceCode equals: 'False'.
6915+
self assert: (self topEntity isOfType: FASTPyBoolean).
6916+
self assert: (self topEntity isOfType: FASTTBooleanLiteral).
6917+
self assert: (self topEntity isOfType: FASTTLiteral).
6918+
stack pop.
6919+
stack pop.
6920+
6921+
"Testing value of monovalue relation value"
6922+
self assert: self topEntity value isNotNil.
6923+
6924+
stack push: self topEntity value.
6925+
self assert: self topEntity sourceCode equals: 'lst'.
6926+
self assert: (self topEntity isOfType: FASTPyIdentifier)
6927+
]
6928+
68786929
{ #category : 'tests - subscripts' }
68796930
FASTPythonImporterTest >> testSliceCall [
68806931
<generated>
@@ -6943,6 +6994,78 @@ FASTPythonImporterTest >> testSliceCall [
69436994
self assert: (self topEntity isOfType: FASTPyIdentifier)
69446995
]
69456996

6997+
{ #category : 'tests - subscripts' }
6998+
FASTPythonImporterTest >> testSliceConditionalExpression [
6999+
<generated>
7000+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
7001+
Regenerate executing: self regenerateTest: #testSliceConditionalExpression "
7002+
7003+
self parse: 'lst[a if cond else b:c]'.
7004+
7005+
self assert: (fast allWithType: FASTPyConditionalExpression) size equals: 1.
7006+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 5.
7007+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
7008+
self assert: (fast allWithType: FASTPySlice) size equals: 1.
7009+
self assert: (fast allWithType: FASTPySubscript) size equals: 1.
7010+
7011+
stack push: fast rootEntities anyOne containedEntities first.
7012+
self assert: self topEntity sourceCode equals: 'lst[a if cond else b:c]'.
7013+
self assert: (self topEntity isOfType: FASTPySubscript).
7014+
7015+
"Testing value of multivalued relation indices"
7016+
self assert: self topEntity indices size equals: 1.
7017+
7018+
stack push: (stack top indices at: 1).
7019+
self assert: self topEntity sourceCode equals: 'a if cond else b:c'.
7020+
self assert: (self topEntity isOfType: FASTPySlice).
7021+
7022+
"Testing value of multivalued relation components"
7023+
self assert: self topEntity components size equals: 2.
7024+
7025+
stack push: (stack top components at: 1).
7026+
self assert: self topEntity sourceCode equals: 'a if cond else b'.
7027+
self assert: (self topEntity isOfType: FASTPyConditionalExpression).
7028+
self assert: (self topEntity isOfType: FASTTWithCondition).
7029+
7030+
"Testing value of monovalue relation condition"
7031+
self assert: self topEntity condition isNotNil.
7032+
7033+
stack push: self topEntity condition.
7034+
self assert: self topEntity sourceCode equals: 'cond'.
7035+
self assert: (self topEntity isOfType: FASTPyIdentifier).
7036+
stack pop.
7037+
7038+
"Testing value of monovalue relation elseExpression"
7039+
self assert: self topEntity elseExpression isNotNil.
7040+
7041+
stack push: self topEntity elseExpression.
7042+
self assert: self topEntity sourceCode equals: 'b'.
7043+
self assert: (self topEntity isOfType: FASTPyIdentifier).
7044+
stack pop.
7045+
7046+
"Testing value of monovalue relation thenExpression"
7047+
self assert: self topEntity thenExpression isNotNil.
7048+
7049+
stack push: self topEntity thenExpression.
7050+
self assert: self topEntity sourceCode equals: 'a'.
7051+
self assert: (self topEntity isOfType: FASTPyIdentifier).
7052+
stack pop.
7053+
stack pop.
7054+
7055+
stack push: (stack top components at: 2).
7056+
self assert: self topEntity sourceCode equals: 'c'.
7057+
self assert: (self topEntity isOfType: FASTPyIdentifier).
7058+
stack pop.
7059+
stack pop.
7060+
7061+
"Testing value of monovalue relation value"
7062+
self assert: self topEntity value isNotNil.
7063+
7064+
stack push: self topEntity value.
7065+
self assert: self topEntity sourceCode equals: 'lst'.
7066+
self assert: (self topEntity isOfType: FASTPyIdentifier)
7067+
]
7068+
69467069
{ #category : 'tests - subscripts' }
69477070
FASTPythonImporterTest >> testSliceEmpty [
69487071
<generated>
@@ -7972,6 +8095,79 @@ FASTPythonImporterTest >> testSubscriptWithTwoIndicies [
79728095
self assert: (self topEntity isOfType: FASTPyIdentifier)
79738096
]
79748097

8098+
{ #category : 'tests - subscripts' }
8099+
FASTPythonImporterTest >> testSubscriptWithTwoSlices [
8100+
<generated>
8101+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
8102+
Regenerate executing: self regenerateTest: #testSubscriptWithTwoSlices "
8103+
8104+
self parse: 'arr[1:3, 2:4] '.
8105+
8106+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 1.
8107+
self assert: (fast allWithType: FASTPyInteger) size equals: 4.
8108+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
8109+
self assert: (fast allWithType: FASTPySlice) size equals: 2.
8110+
self assert: (fast allWithType: FASTPySubscript) size equals: 1.
8111+
8112+
stack push: fast rootEntities anyOne containedEntities first.
8113+
self assert: self topEntity sourceCode equals: 'arr[1:3, 2:4]'.
8114+
self assert: (self topEntity isOfType: FASTPySubscript).
8115+
8116+
"Testing value of multivalued relation indices"
8117+
self assert: self topEntity indices size equals: 2.
8118+
8119+
stack push: (stack top indices at: 1).
8120+
self assert: self topEntity sourceCode equals: '1:3'.
8121+
self assert: (self topEntity isOfType: FASTPySlice).
8122+
8123+
"Testing value of multivalued relation components"
8124+
self assert: self topEntity components size equals: 2.
8125+
8126+
stack push: (stack top components at: 1).
8127+
self assert: self topEntity sourceCode equals: '1'.
8128+
self assert: (self topEntity isOfType: FASTPyInteger).
8129+
self assert: (self topEntity isOfType: FASTTLiteral).
8130+
self assert: (self topEntity isOfType: FASTTNumericalLiteral).
8131+
stack pop.
8132+
8133+
stack push: (stack top components at: 2).
8134+
self assert: self topEntity sourceCode equals: '3'.
8135+
self assert: (self topEntity isOfType: FASTPyInteger).
8136+
self assert: (self topEntity isOfType: FASTTLiteral).
8137+
self assert: (self topEntity isOfType: FASTTNumericalLiteral).
8138+
stack pop.
8139+
stack pop.
8140+
8141+
stack push: (stack top indices at: 2).
8142+
self assert: self topEntity sourceCode equals: '2:4'.
8143+
self assert: (self topEntity isOfType: FASTPySlice).
8144+
8145+
"Testing value of multivalued relation components"
8146+
self assert: self topEntity components size equals: 2.
8147+
8148+
stack push: (stack top components at: 1).
8149+
self assert: self topEntity sourceCode equals: '2'.
8150+
self assert: (self topEntity isOfType: FASTPyInteger).
8151+
self assert: (self topEntity isOfType: FASTTLiteral).
8152+
self assert: (self topEntity isOfType: FASTTNumericalLiteral).
8153+
stack pop.
8154+
8155+
stack push: (stack top components at: 2).
8156+
self assert: self topEntity sourceCode equals: '4'.
8157+
self assert: (self topEntity isOfType: FASTPyInteger).
8158+
self assert: (self topEntity isOfType: FASTTLiteral).
8159+
self assert: (self topEntity isOfType: FASTTNumericalLiteral).
8160+
stack pop.
8161+
stack pop.
8162+
8163+
"Testing value of monovalue relation value"
8164+
self assert: self topEntity value isNotNil.
8165+
8166+
stack push: self topEntity value.
8167+
self assert: self topEntity sourceCode equals: 'arr'.
8168+
self assert: (self topEntity isOfType: FASTPyIdentifier)
8169+
]
8170+
79758171
{ #category : 'tests - literals' }
79768172
FASTPythonImporterTest >> testTrue [
79778173

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ FASTPythonImporter class >> devFASTPythonMenu: aBuilder [
1414

1515
<worldMenu>
1616
(aBuilder item: #DevFASTPython)
17-
"parent: #Famix; uncomment later when the dev will be more advanced."
1817
order: 100;
1918
label: 'FAST Python dev utilities';
19+
"parent: #Famix; uncomment later when the dev will be more advanced."
2020
icon: MooseIcons mooseIcon;
2121
with: [
2222
(aBuilder item: #ResetMM)
@@ -27,14 +27,19 @@ FASTPythonImporter class >> devFASTPythonMenu: aBuilder [
2727
(aBuilder item: #ImportBatch1)
2828
label: 'Import batch 1';
2929
order: 2;
30-
icon: (self iconNamed: #smallNew);
30+
icon: (self iconNamed: #smallNew);
3131
action: [ self devParseBatch1 ].
32+
(aBuilder item: #ImportBatch1To10)
33+
label: 'Import batch 1 to 10';
34+
order: 2;
35+
icon: (self iconNamed: #smallNew);
36+
action: [ self devParseFiles: ('/Users/cyril/marius/10batches' asFileReference allFiles select: [ :f | f extension = 'py' ]) ].
3237
(aBuilder item: #'Toggle FAST Importer Debug mode')
3338
action: [ TSFASTImporter isInDebugMode: TSFASTImporter isInDebugMode not ];
3439
order: 99999;
3540
withSeparatorAfter;
3641
help: 'If this is enabled, errors will not be caught in the FAST importing but passed.';
37-
icon: (self iconNamed: #configuration) ]
42+
icon: (self iconNamed: #configuration) ]
3843
]
3944

4045
{ #category : 'development support' }
@@ -59,7 +64,7 @@ FASTPythonImporter class >> devParseBatchNumber: aString [
5964
We do not save the models to not flood the memory and allow their GC."
6065

6166
<script>
62-
self devParseFiles: (('/Users/cyril/marius/selected_notebooks_converted/batch_' , aString) asFileReference files select: [ :f | f extension = 'py' ])
67+
self devParseFiles: (('/Users/cyril/marius/selected_notebooks_converted/batch_' , aString) asFileReference allFiles select: [ :f | f extension = 'py' ])
6368
]
6469

6570
{ #category : 'development support' }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ TSFASTPythonImporter >> visitIdentifier: aNode [
355355
{ FASTPyMethodDefinition. FASTPyClassDefinition. FASTPyFunctionDefinition. FASTPyKeywordArgument } anySatisfy: [ :class | entry isOfFASTType: class ] ] ]) ifTrue: [ ^ self topFastEntity name: (self sourceCodeOf: aNode) ].
356356

357357
"If I am on the left side of an assignation then I am a variable."
358-
(context anySatisfy: [ :entry | entry field = #left and: [ entry isOfFASTType: FASTPyAssignment ] ]) ifTrue: [
358+
(context top field = #left and: [ context top isOfFASTType: FASTPyAssignment ]) ifTrue: [
359359
^ self handleNode: aNode kind: FASTPyVariable ].
360360

361361
"In case we are in an alias, we edit the property alias of the last imported entity"

0 commit comments

Comments
 (0)