Skip to content

Commit 6c833f2

Browse files
committed
Make withStatement a statement and skip the as_pattern_target node
1 parent f8d7f30 commit 6c833f2

6 files changed

Lines changed: 221 additions & 28 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Class {
66
'_ERROR',
77
'tEntity',
88
'asPattern',
9-
'asPatternTarget',
109
'assertStatement',
1110
'assignment',
1211
'attribute',
@@ -186,7 +185,6 @@ FASTPythonMetamodelGenerator >> defineClasses [
186185
entity := builder ensureClassNamed: #Entity.
187186
_ERROR := builder ensureClassNamed: #ERROR.
188187
asPattern := builder ensureClassNamed: #AsPattern."Todo"
189-
asPatternTarget := builder ensureClassNamed: #AsPatternTarget."Todo"
190188
assertStatement := builder ensureClassNamed: #AssertStatement.
191189
assignment := builder ensureClassNamed: #Assignment."To review"
192190
attribute := builder ensureClassNamed: #AttributeAccess.
@@ -513,7 +511,9 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
513511

514512
whileStatement --|> statement.
515513
whileStatement --|> tConditionalStatement.
516-
whileStatement --|> tLoopStatement
514+
whileStatement --|> tLoopStatement.
515+
516+
withStatement --|> statement
517517
]
518518

519519
{ #category : 'definition' }

‎src/FAST-Python-Model/FASTPyAsPatternTarget.class.st‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ FASTPyTEntityCreator >> newAsPattern [
2727
^ self add: FASTPyAsPattern new
2828
]
2929

30-
{ #category : 'entity creation' }
31-
FASTPyTEntityCreator >> newAsPatternTarget [
32-
33-
<generated>
34-
^ self add: FASTPyAsPatternTarget new
35-
]
36-
3730
{ #category : 'entity creation' }
3831
FASTPyTEntityCreator >> newAssertStatement [
3932

‎src/FAST-Python-Model/FASTPyWithStatement.class.st‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Class {
22
#name : 'FASTPyWithStatement',
3-
#superclass : 'FASTPyEntity',
3+
#superclass : 'FASTPyStatement',
44
#category : 'FAST-Python-Model-Entities',
55
#package : 'FAST-Python-Model',
66
#tag : 'Entities'
@@ -9,7 +9,7 @@ Class {
99
{ #category : 'meta' }
1010
FASTPyWithStatement class >> annotation [
1111

12-
<FMClass: #WithStatement super: #FASTPyEntity>
12+
<FMClass: #WithStatement super: #FASTPyStatement>
1313
<package: #'FAST-Python-Model'>
1414
<generated>
1515
^ self

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

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10444,6 +10444,215 @@ FASTPythonImporterTest >> testWhile [
1044410444
self assert: (self topEntity isOfType: FASTTLiteral)
1044510445
]
1044610446

10447+
{ #category : 'tests - with statement' }
10448+
FASTPythonImporterTest >> testWithStatement [
10449+
<generated>
10450+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
10451+
Regenerate executing: self regenerateTest: #testWithStatement "
10452+
10453+
self parse: 'with open("input.txt") as src, open("output.txt", "w") as dst:
10454+
dst.write(src.read())'.
10455+
10456+
self assert: (fast allWithType: FASTPyAsPattern) size equals: 2.
10457+
self assert: (fast allWithType: FASTPyAttributeAccess) size equals: 2.
10458+
self assert: (fast allWithType: FASTPyBlock) size equals: 1.
10459+
self assert: (fast allWithType: FASTPyCall) size equals: 4.
10460+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 6.
10461+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
10462+
self assert: (fast allWithType: FASTPyString) size equals: 3.
10463+
self assert: (fast allWithType: FASTPyVariable) size equals: 2.
10464+
self assert: (fast allWithType: FASTPyWithClause) size equals: 1.
10465+
self assert: (fast allWithType: FASTPyWithItem) size equals: 2.
10466+
self assert: (fast allWithType: FASTPyWithStatement) size equals: 1.
10467+
10468+
stack push: fast rootEntities anyOne containedEntities first.
10469+
self assert: self topEntity sourceCode equals: 'with open("input.txt") as src, open("output.txt", "w") as dst:
10470+
dst.write(src.read())' withPlatformLineEndings.
10471+
self assert: (self topEntity isOfType: FASTPyWithStatement).
10472+
10473+
"Testing value of multivalued relation genericChildren"
10474+
self assert: self topEntity genericChildren size equals: 2.
10475+
10476+
stack push: (stack top genericChildren at: 1).
10477+
self assert: self topEntity sourceCode equals: 'open("input.txt") as src, open("output.txt", "w") as dst'.
10478+
self assert: (self topEntity isOfType: FASTPyWithClause).
10479+
10480+
"Testing value of multivalued relation genericChildren"
10481+
self assert: self topEntity genericChildren size equals: 2.
10482+
10483+
stack push: (stack top genericChildren at: 1).
10484+
self assert: self topEntity sourceCode equals: 'open("input.txt") as src'.
10485+
self assert: (self topEntity isOfType: FASTPyWithItem).
10486+
10487+
"Testing value of multivalued relation genericChildren"
10488+
self assert: self topEntity genericChildren size equals: 1.
10489+
10490+
stack push: (stack top genericChildren at: 1).
10491+
self assert: self topEntity sourceCode equals: 'open("input.txt") as src'.
10492+
self assert: (self topEntity isOfType: FASTPyAsPattern).
10493+
10494+
"Testing value of multivalued relation genericChildren"
10495+
self assert: self topEntity genericChildren size equals: 2.
10496+
10497+
stack push: (stack top genericChildren at: 1).
10498+
self assert: self topEntity sourceCode equals: 'open("input.txt")'.
10499+
self assert: (self topEntity isOfType: FASTPyCall).
10500+
self assert: (self topEntity isOfType: FASTTInvocation).
10501+
self assert: (self topEntity isOfType: FASTTWithArguments).
10502+
10503+
"Testing value of multivalued relation arguments"
10504+
self assert: self topEntity arguments size equals: 1.
10505+
10506+
stack push: (stack top arguments at: 1).
10507+
self assert: self topEntity sourceCode equals: '"input.txt"'.
10508+
self assert: (self topEntity isOfType: FASTPyString).
10509+
self assert: (self topEntity isOfType: FASTTLiteral).
10510+
self assert: (self topEntity isOfType: FASTTStringLiteral).
10511+
stack pop.
10512+
10513+
"Testing value of monovalue relation callee"
10514+
self assert: self topEntity callee isNotNil.
10515+
10516+
stack push: self topEntity callee.
10517+
self assert: self topEntity sourceCode equals: 'open'.
10518+
self assert: (self topEntity isOfType: FASTPyIdentifier).
10519+
stack pop.
10520+
stack pop.
10521+
10522+
stack push: (stack top genericChildren at: 2).
10523+
self assert: self topEntity sourceCode equals: 'src'.
10524+
self assert: (self topEntity isOfType: FASTPyIdentifier).
10525+
stack pop.
10526+
stack pop.
10527+
stack pop.
10528+
10529+
stack push: (stack top genericChildren at: 2).
10530+
self assert: self topEntity sourceCode equals: 'open("output.txt", "w") as dst'.
10531+
self assert: (self topEntity isOfType: FASTPyWithItem).
10532+
10533+
"Testing value of multivalued relation genericChildren"
10534+
self assert: self topEntity genericChildren size equals: 1.
10535+
10536+
stack push: (stack top genericChildren at: 1).
10537+
self assert: self topEntity sourceCode equals: 'open("output.txt", "w") as dst'.
10538+
self assert: (self topEntity isOfType: FASTPyAsPattern).
10539+
10540+
"Testing value of multivalued relation genericChildren"
10541+
self assert: self topEntity genericChildren size equals: 2.
10542+
10543+
stack push: (stack top genericChildren at: 1).
10544+
self assert: self topEntity sourceCode equals: 'open("output.txt", "w")'.
10545+
self assert: (self topEntity isOfType: FASTPyCall).
10546+
self assert: (self topEntity isOfType: FASTTInvocation).
10547+
self assert: (self topEntity isOfType: FASTTWithArguments).
10548+
10549+
"Testing value of multivalued relation arguments"
10550+
self assert: self topEntity arguments size equals: 2.
10551+
10552+
stack push: (stack top arguments at: 1).
10553+
self assert: self topEntity sourceCode equals: '"output.txt"'.
10554+
self assert: (self topEntity isOfType: FASTPyString).
10555+
self assert: (self topEntity isOfType: FASTTLiteral).
10556+
self assert: (self topEntity isOfType: FASTTStringLiteral).
10557+
stack pop.
10558+
10559+
stack push: (stack top arguments at: 2).
10560+
self assert: self topEntity sourceCode equals: '"w"'.
10561+
self assert: (self topEntity isOfType: FASTPyString).
10562+
self assert: (self topEntity isOfType: FASTTLiteral).
10563+
self assert: (self topEntity isOfType: FASTTStringLiteral).
10564+
stack pop.
10565+
10566+
"Testing value of monovalue relation callee"
10567+
self assert: self topEntity callee isNotNil.
10568+
10569+
stack push: self topEntity callee.
10570+
self assert: self topEntity sourceCode equals: 'open'.
10571+
self assert: (self topEntity isOfType: FASTPyIdentifier).
10572+
stack pop.
10573+
stack pop.
10574+
10575+
stack push: (stack top genericChildren at: 2).
10576+
self assert: self topEntity sourceCode equals: 'dst'.
10577+
self assert: (self topEntity isOfType: FASTPyIdentifier).
10578+
stack pop.
10579+
stack pop.
10580+
stack pop.
10581+
stack pop.
10582+
10583+
stack push: (stack top genericChildren at: 2).
10584+
self assert: self topEntity sourceCode equals: 'dst.write(src.read())'.
10585+
self assert: (self topEntity isOfType: FASTPyBlock).
10586+
self assert: (self topEntity isOfType: FASTTStatementBlock).
10587+
10588+
"Testing value of multivalued relation statements"
10589+
self assert: self topEntity statements size equals: 1.
10590+
10591+
stack push: (stack top statements at: 1).
10592+
self assert: self topEntity sourceCode equals: 'dst.write(src.read())'.
10593+
self assert: (self topEntity isOfType: FASTPyCall).
10594+
self assert: (self topEntity isOfType: FASTTInvocation).
10595+
self assert: (self topEntity isOfType: FASTTWithArguments).
10596+
10597+
"Testing value of multivalued relation arguments"
10598+
self assert: self topEntity arguments size equals: 1.
10599+
10600+
stack push: (stack top arguments at: 1).
10601+
self assert: self topEntity sourceCode equals: 'src.read()'.
10602+
self assert: (self topEntity isOfType: FASTPyCall).
10603+
self assert: (self topEntity isOfType: FASTTInvocation).
10604+
self assert: (self topEntity isOfType: FASTTWithArguments).
10605+
10606+
"Testing value of monovalue relation callee"
10607+
self assert: self topEntity callee isNotNil.
10608+
10609+
stack push: self topEntity callee.
10610+
self assert: self topEntity sourceCode equals: 'src.read'.
10611+
self assert: (self topEntity isOfType: FASTPyAttributeAccess).
10612+
10613+
"Testing value of monovalue relation attribute"
10614+
self assert: self topEntity attribute isNotNil.
10615+
10616+
stack push: self topEntity attribute.
10617+
self assert: self topEntity sourceCode equals: 'read'.
10618+
self assert: (self topEntity isOfType: FASTPyVariable).
10619+
self assert: (self topEntity isOfType: FASTTVariableEntity).
10620+
stack pop.
10621+
10622+
"Testing value of monovalue relation object"
10623+
self assert: self topEntity object isNotNil.
10624+
10625+
stack push: self topEntity object.
10626+
self assert: self topEntity sourceCode equals: 'src'.
10627+
self assert: (self topEntity isOfType: FASTPyIdentifier).
10628+
stack pop.
10629+
stack pop.
10630+
stack pop.
10631+
10632+
"Testing value of monovalue relation callee"
10633+
self assert: self topEntity callee isNotNil.
10634+
10635+
stack push: self topEntity callee.
10636+
self assert: self topEntity sourceCode equals: 'dst.write'.
10637+
self assert: (self topEntity isOfType: FASTPyAttributeAccess).
10638+
10639+
"Testing value of monovalue relation attribute"
10640+
self assert: self topEntity attribute isNotNil.
10641+
10642+
stack push: self topEntity attribute.
10643+
self assert: self topEntity sourceCode equals: 'write'.
10644+
self assert: (self topEntity isOfType: FASTPyVariable).
10645+
self assert: (self topEntity isOfType: FASTTVariableEntity).
10646+
stack pop.
10647+
10648+
"Testing value of monovalue relation object"
10649+
self assert: self topEntity object isNotNil.
10650+
10651+
stack push: self topEntity object.
10652+
self assert: self topEntity sourceCode equals: 'dst'.
10653+
self assert: (self topEntity isOfType: FASTPyIdentifier)
10654+
]
10655+
1044710656
{ #category : 'running' }
1044810657
FASTPythonImporterTest >> topEntity [
1044910658

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ TSFASTPythonImporter >> visitArgumentList: aTSNode [
5151
self rawVisitChildren: aTSNode
5252
]
5353

54+
{ #category : 'visiting - skip' }
55+
TSFASTPythonImporter >> visitAsPatternTarget: aTSNode [
56+
"Nothing to do. The visit of my child will take care of things. I use the #raw version since it is what should be used to skip a context level."
57+
58+
self rawVisitChildren: aTSNode
59+
]
60+
5461
{ #category : 'visiting - alias' }
5562
TSFASTPythonImporter >> visitAssertStatement: aTSNode [
5663

0 commit comments

Comments
 (0)