Skip to content

Commit 60dd968

Browse files
committed
Finish to manage the as pattern of a with statement.
It is still needed to manage some children in case of a case pattern.
1 parent d2823a7 commit 60dd968

5 files changed

Lines changed: 265 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
329329
attribute --|> tDecoratorExpression.
330330
attribute --|> tCanBeSplatExpression.
331331
attribute --|> tAsPatternTarget.
332+
attribute --|> tAsPatternSource.
332333

333334
augmentedAssignment --|> statement.
334335

@@ -420,6 +421,7 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
420421
identifier --|> tDecoratorExpression.
421422
identifier --|> tCanBeSplatExpression.
422423
identifier --|> tAsPatternTarget.
424+
identifier --|> tAsPatternSource.
423425

424426
ifClause --|> expression. "This is wrong! I am just here temporarily until we rework the relation to the for in clause (I need to be able to be a clause of a list comprehension)"
425427

@@ -499,6 +501,9 @@ FASTPythonMetamodelGenerator >> defineHierarchy [
499501
subscript --|> tDecoratorExpression.
500502
subscript --|> tCanBeSplatExpression.
501503
subscript --|> tAsPatternTarget.
504+
subscript --|> tAsPatternSource.
505+
506+
tAsPatternTarget --|> tAsPatternSource.
502507

503508
tComprehension --|> tCanBeSplatExpression.
504509

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Parents
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
8+
| `parentAsPatternSource` | `FASTPyTAsPatternSource` | `source` | `FASTPyAsPattern` | |
89
| `parentAsPatternTarget` | `FASTPyTAsPatternTarget` | `target` | `FASTPyAsPattern` | |
910
| `parentDeclarator` | `FASTPyTDecoratorExpression` | `expression` | `FASTPyDecorator` | |
1011
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
@@ -21,8 +22,8 @@
2122
Class {
2223
#name : 'FASTPyAttributeAccess',
2324
#superclass : 'FASTPyExpression',
24-
#traits : 'FASTPyTAsPatternTarget + FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
25-
#classTraits : 'FASTPyTAsPatternTarget classTrait + FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
25+
#traits : 'FASTPyTAsPatternSource + FASTPyTAsPatternTarget + FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
26+
#classTraits : 'FASTPyTAsPatternSource classTrait + FASTPyTAsPatternTarget classTrait + FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
2627
#instVars : [
2728
'#attribute => FMOne type: #FASTPyVariable opposite: #attributeOwner',
2829
'#object => FMOne type: #FASTPyExpression opposite: #attributeObjectOwner'

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Parents
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
8+
| `parentAsPatternSource` | `FASTPyTAsPatternSource` | `source` | `FASTPyAsPattern` | |
89
| `parentAsPatternTarget` | `FASTPyTAsPatternTarget` | `target` | `FASTPyAsPattern` | |
910
| `parentDeclarator` | `FASTPyTDecoratorExpression` | `expression` | `FASTPyDecorator` | |
1011
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
@@ -15,8 +16,8 @@
1516
Class {
1617
#name : 'FASTPyIdentifier',
1718
#superclass : 'FASTPyExpression',
18-
#traits : 'FASTPyTAsPatternTarget + FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
19-
#classTraits : 'FASTPyTAsPatternTarget classTrait + FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
19+
#traits : 'FASTPyTAsPatternSource + FASTPyTAsPatternTarget + FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
20+
#classTraits : 'FASTPyTAsPatternSource classTrait + FASTPyTAsPatternTarget classTrait + FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
2021
#category : 'FAST-Python-Model-Entities',
2122
#package : 'FAST-Python-Model',
2223
#tag : 'Entities'

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Parents
66
| Relation | Origin | Opposite | Type | Comment |
77
|---|
8+
| `parentAsPatternSource` | `FASTPyTAsPatternSource` | `source` | `FASTPyAsPattern` | |
89
| `parentAsPatternTarget` | `FASTPyTAsPatternTarget` | `target` | `FASTPyAsPattern` | |
910
| `parentDeclarator` | `FASTPyTDecoratorExpression` | `expression` | `FASTPyDecorator` | |
1011
| `parentSplat` | `FASTPyTCanBeSplatExpression` | `expression` | `FASTPyCollectionSplat` | |
@@ -21,8 +22,8 @@
2122
Class {
2223
#name : 'FASTPySubscript',
2324
#superclass : 'FASTPyExpression',
24-
#traits : 'FASTPyTAsPatternTarget + FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
25-
#classTraits : 'FASTPyTAsPatternTarget classTrait + FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
25+
#traits : 'FASTPyTAsPatternSource + FASTPyTAsPatternTarget + FASTPyTCanBeSplatExpression + FASTPyTDecoratorExpression',
26+
#classTraits : 'FASTPyTAsPatternSource classTrait + FASTPyTAsPatternTarget classTrait + FASTPyTCanBeSplatExpression classTrait + FASTPyTDecoratorExpression classTrait',
2627
#instVars : [
2728
'#indices => FMMany type: #FASTPyExpression opposite: #subscriptIndiceOwner',
2829
'#value => FMOne type: #FASTPyExpression opposite: #subscriptValueOwner'

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

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,257 @@ FASTPythonImporterTest >> testAsPatternWithList [
272272
self assert: (self topEntity isOfType: FASTPyPassStatement)
273273
]
274274

275+
{ #category : 'tests - with statement' }
276+
FASTPythonImporterTest >> testAsPatternWithSourceAttributeAccess [
277+
<generated>
278+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
279+
Regenerate executing: self regenerateTest: #testAsPatternWithSourceAttributeAccess "
280+
281+
self parse: 'with x.y as f: pass'.
282+
283+
self assert: (fast allWithType: FASTPyAsPattern) size equals: 1.
284+
self assert: (fast allWithType: FASTPyAttributeAccess) size equals: 1.
285+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 2.
286+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
287+
self assert: (fast allWithType: FASTPyPassStatement) size equals: 1.
288+
self assert: (fast allWithType: FASTPyVariable) size equals: 1.
289+
self assert: (fast allWithType: FASTPyWithStatement) size equals: 1.
290+
291+
stack push: fast rootEntities anyOne containedEntities first.
292+
self assert: self topEntity sourceCode equals: 'with x.y as f: pass'.
293+
self assert: (self topEntity isOfType: FASTPyWithStatement).
294+
self assert: (self topEntity isOfType: FASTTStatementBlock).
295+
296+
"Testing value of multivalued relation items"
297+
self assert: self topEntity items size equals: 1.
298+
299+
stack push: (stack top items at: 1).
300+
self assert: self topEntity sourceCode equals: 'x.y as f'.
301+
self assert: (self topEntity isOfType: FASTPyAsPattern).
302+
303+
"Testing value of monovalue relation source"
304+
self assert: self topEntity source isNotNil.
305+
306+
stack push: self topEntity source.
307+
self assert: self topEntity sourceCode equals: 'x.y'.
308+
self assert: (self topEntity isOfType: FASTPyAttributeAccess).
309+
310+
"Testing value of monovalue relation attribute"
311+
self assert: self topEntity attribute isNotNil.
312+
313+
stack push: self topEntity attribute.
314+
self assert: self topEntity sourceCode equals: 'y'.
315+
self assert: (self topEntity isOfType: FASTPyVariable).
316+
self assert: (self topEntity isOfType: FASTTVariableEntity).
317+
stack pop.
318+
319+
"Testing value of monovalue relation object"
320+
self assert: self topEntity object isNotNil.
321+
322+
stack push: self topEntity object.
323+
self assert: self topEntity sourceCode equals: 'x'.
324+
self assert: (self topEntity isOfType: FASTPyIdentifier).
325+
stack pop.
326+
stack pop.
327+
328+
"Testing value of monovalue relation target"
329+
self assert: self topEntity target isNotNil.
330+
331+
stack push: self topEntity target.
332+
self assert: self topEntity sourceCode equals: 'f'.
333+
self assert: (self topEntity isOfType: FASTPyIdentifier).
334+
stack pop.
335+
stack pop.
336+
337+
"Testing value of multivalued relation statements"
338+
self assert: self topEntity statements size equals: 1.
339+
340+
stack push: (stack top statements at: 1).
341+
self assert: self topEntity sourceCode equals: 'pass'.
342+
self assert: (self topEntity isOfType: FASTPyPassStatement)
343+
]
344+
345+
{ #category : 'tests - with statement' }
346+
FASTPythonImporterTest >> testAsPatternWithSourceCall [
347+
<generated>
348+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
349+
Regenerate executing: self regenerateTest: #testAsPatternWithSourceCall "
350+
351+
self parse: 'with x() as f: pass'.
352+
353+
self assert: (fast allWithType: FASTPyAsPattern) size equals: 1.
354+
self assert: (fast allWithType: FASTPyCall) size equals: 1.
355+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 2.
356+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
357+
self assert: (fast allWithType: FASTPyPassStatement) size equals: 1.
358+
self assert: (fast allWithType: FASTPyWithStatement) size equals: 1.
359+
360+
stack push: fast rootEntities anyOne containedEntities first.
361+
self assert: self topEntity sourceCode equals: 'with x() as f: pass'.
362+
self assert: (self topEntity isOfType: FASTPyWithStatement).
363+
self assert: (self topEntity isOfType: FASTTStatementBlock).
364+
365+
"Testing value of multivalued relation items"
366+
self assert: self topEntity items size equals: 1.
367+
368+
stack push: (stack top items at: 1).
369+
self assert: self topEntity sourceCode equals: 'x() as f'.
370+
self assert: (self topEntity isOfType: FASTPyAsPattern).
371+
372+
"Testing value of monovalue relation source"
373+
self assert: self topEntity source isNotNil.
374+
375+
stack push: self topEntity source.
376+
self assert: self topEntity sourceCode equals: 'x()'.
377+
self assert: (self topEntity isOfType: FASTPyCall).
378+
self assert: (self topEntity isOfType: FASTTInvocation).
379+
self assert: (self topEntity isOfType: FASTTWithArguments).
380+
381+
"Testing value of monovalue relation callee"
382+
self assert: self topEntity callee isNotNil.
383+
384+
stack push: self topEntity callee.
385+
self assert: self topEntity sourceCode equals: 'x'.
386+
self assert: (self topEntity isOfType: FASTPyIdentifier).
387+
stack pop.
388+
stack pop.
389+
390+
"Testing value of monovalue relation target"
391+
self assert: self topEntity target isNotNil.
392+
393+
stack push: self topEntity target.
394+
self assert: self topEntity sourceCode equals: 'f'.
395+
self assert: (self topEntity isOfType: FASTPyIdentifier).
396+
stack pop.
397+
stack pop.
398+
399+
"Testing value of multivalued relation statements"
400+
self assert: self topEntity statements size equals: 1.
401+
402+
stack push: (stack top statements at: 1).
403+
self assert: self topEntity sourceCode equals: 'pass'.
404+
self assert: (self topEntity isOfType: FASTPyPassStatement)
405+
]
406+
407+
{ #category : 'tests - with statement' }
408+
FASTPythonImporterTest >> testAsPatternWithSourceIdentifier [
409+
<generated>
410+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
411+
Regenerate executing: self regenerateTest: #testAsPatternWithSourceIdentifier "
412+
413+
self parse: 'with x as f: pass'.
414+
415+
self assert: (fast allWithType: FASTPyAsPattern) size equals: 1.
416+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 2.
417+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
418+
self assert: (fast allWithType: FASTPyPassStatement) size equals: 1.
419+
self assert: (fast allWithType: FASTPyWithStatement) size equals: 1.
420+
421+
stack push: fast rootEntities anyOne containedEntities first.
422+
self assert: self topEntity sourceCode equals: 'with x as f: pass'.
423+
self assert: (self topEntity isOfType: FASTPyWithStatement).
424+
self assert: (self topEntity isOfType: FASTTStatementBlock).
425+
426+
"Testing value of multivalued relation items"
427+
self assert: self topEntity items size equals: 1.
428+
429+
stack push: (stack top items at: 1).
430+
self assert: self topEntity sourceCode equals: 'x as f'.
431+
self assert: (self topEntity isOfType: FASTPyAsPattern).
432+
433+
"Testing value of monovalue relation source"
434+
self assert: self topEntity source isNotNil.
435+
436+
stack push: self topEntity source.
437+
self assert: self topEntity sourceCode equals: 'x'.
438+
self assert: (self topEntity isOfType: FASTPyIdentifier).
439+
stack pop.
440+
441+
"Testing value of monovalue relation target"
442+
self assert: self topEntity target isNotNil.
443+
444+
stack push: self topEntity target.
445+
self assert: self topEntity sourceCode equals: 'f'.
446+
self assert: (self topEntity isOfType: FASTPyIdentifier).
447+
stack pop.
448+
stack pop.
449+
450+
"Testing value of multivalued relation statements"
451+
self assert: self topEntity statements size equals: 1.
452+
453+
stack push: (stack top statements at: 1).
454+
self assert: self topEntity sourceCode equals: 'pass'.
455+
self assert: (self topEntity isOfType: FASTPyPassStatement)
456+
]
457+
458+
{ #category : 'tests - with statement' }
459+
FASTPythonImporterTest >> testAsPatternWithSourceSubscript [
460+
<generated>
461+
"Generated as regression test by FASTPyImporterTestGenerator>>#generateTestNamed:fromCode:protocol:
462+
Regenerate executing: self regenerateTest: #testAsPatternWithSourceSubscript "
463+
464+
self parse: 'with x[y] as f: pass'.
465+
466+
self assert: (fast allWithType: FASTPyAsPattern) size equals: 1.
467+
self assert: (fast allWithType: FASTPyIdentifier) size equals: 3.
468+
self assert: (fast allWithType: FASTPyModule) size equals: 1.
469+
self assert: (fast allWithType: FASTPyPassStatement) size equals: 1.
470+
self assert: (fast allWithType: FASTPySubscript) size equals: 1.
471+
self assert: (fast allWithType: FASTPyWithStatement) size equals: 1.
472+
473+
stack push: fast rootEntities anyOne containedEntities first.
474+
self assert: self topEntity sourceCode equals: 'with x[y] as f: pass'.
475+
self assert: (self topEntity isOfType: FASTPyWithStatement).
476+
self assert: (self topEntity isOfType: FASTTStatementBlock).
477+
478+
"Testing value of multivalued relation items"
479+
self assert: self topEntity items size equals: 1.
480+
481+
stack push: (stack top items at: 1).
482+
self assert: self topEntity sourceCode equals: 'x[y] as f'.
483+
self assert: (self topEntity isOfType: FASTPyAsPattern).
484+
485+
"Testing value of monovalue relation source"
486+
self assert: self topEntity source isNotNil.
487+
488+
stack push: self topEntity source.
489+
self assert: self topEntity sourceCode equals: 'x[y]'.
490+
self assert: (self topEntity isOfType: FASTPySubscript).
491+
492+
"Testing value of multivalued relation indices"
493+
self assert: self topEntity indices size equals: 1.
494+
495+
stack push: (stack top indices at: 1).
496+
self assert: self topEntity sourceCode equals: 'y'.
497+
self assert: (self topEntity isOfType: FASTPyIdentifier).
498+
stack pop.
499+
500+
"Testing value of monovalue relation value"
501+
self assert: self topEntity value isNotNil.
502+
503+
stack push: self topEntity value.
504+
self assert: self topEntity sourceCode equals: 'x'.
505+
self assert: (self topEntity isOfType: FASTPyIdentifier).
506+
stack pop.
507+
stack pop.
508+
509+
"Testing value of monovalue relation target"
510+
self assert: self topEntity target isNotNil.
511+
512+
stack push: self topEntity target.
513+
self assert: self topEntity sourceCode equals: 'f'.
514+
self assert: (self topEntity isOfType: FASTPyIdentifier).
515+
stack pop.
516+
stack pop.
517+
518+
"Testing value of multivalued relation statements"
519+
self assert: self topEntity statements size equals: 1.
520+
521+
stack push: (stack top statements at: 1).
522+
self assert: self topEntity sourceCode equals: 'pass'.
523+
self assert: (self topEntity isOfType: FASTPyPassStatement)
524+
]
525+
275526
{ #category : 'tests - with statement' }
276527
FASTPythonImporterTest >> testAsPatternWithSubscript [
277528
<generated>

0 commit comments

Comments
 (0)