Repository navigation
Expand file tree
/
Copy pathFASTPythonImporter.class.st
More file actions
148 lines (116 loc) · 4.34 KB
/
Copy pathFASTPythonImporter.class.st
File metadata and controls
148 lines (116 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"
I am a FAST Python importer.
I declare the TreeSitter Python language to use and redirect the visit to `FASTPythonTreeSitterVisitor`, which builds the `FASTPy*` model entities.
## Usage
```smalltalk
model := FASTPythonImporter parseFile: aFile.
model := FASTPythonImporter parse: 'print(1)'.
```
## Documentation
For more information about doing analysis on the imported model you can read the [analysis documentation](https://github.com/moosetechnology/FAST-Python/blob/main/resources/doc/analysis.md).
"
Class {
#name : 'FASTPythonImporter',
#superclass : 'TSFASTAbstractImporter',
#category : 'FAST-Python-Tools-Importing',
#package : 'FAST-Python-Tools',
#tag : 'Importing'
}
{ #category : 'world menu' }
FASTPythonImporter class >> devFASTPythonMenu: aBuilder [
<worldMenu>
<ignoreForCoverage>
(aBuilder item: #DevFASTPython)
order: 100;
label: 'FAST Python dev utilities';
"parent: #Famix; uncomment later when the dev will be more advanced."
icon: MooseIcons mooseIcon;
with: [
(aBuilder item: #ResetMM)
label: 'Regenerate MM';
order: 1;
icon: (self iconNamed: #refresh);
action: [ FASTPythonMetamodelGenerator new generate ].
(aBuilder item: #ImportBatch1)
label: 'Import batch 1';
order: 2;
icon: (self iconNamed: #smallNew);
action: [ self devParseBatch1 ].
(aBuilder item: #ImportBatch1To10)
label: 'Import batch 1 to 10';
order: 2;
icon: (self iconNamed: #smallNew);
action: [ self devParseFiles: ('/Users/cyril/marius/10batches' asFileReference allFiles select: [ :f | f extension = 'py' ]) ].
(aBuilder item: #'Toggle FAST Importer Debug mode')
action: [ TSFASTVisitor isInDebugMode: TSFASTVisitor isInDebugMode not ];
order: 99999;
withSeparatorAfter;
help: 'If this is enabled, errors will not be caught in the FAST importing but passed.';
icon: (self iconNamed: #configuration) ]
]
{ #category : 'development support' }
FASTPythonImporter class >> devParseAll [
"Command specific to help me develop. this is useful to know the file to parse everything and detect if this raises any error.
We do not save the models to not flood the memory and allow their GC."
<script>
<ignoreForCoverage>
self devParseFiles: ('/Users/cyril/marius/selected_notebooks_converted' asFileReference allFiles select: [ :f | f extension = 'py' ])
]
{ #category : 'development support' }
FASTPythonImporter class >> devParseBatch1 [
<script>
<ignoreForCoverage>
[ self devParseBatchNumber: '001' ] spy
]
{ #category : 'development support' }
FASTPythonImporter class >> devParseBatchNumber: aString [
"Command specific to help me develop. this is useful to know the file to parse everything and detect if this raises any error.
We do not save the models to not flood the memory and allow their GC."
<script>
<ignoreForCoverage>
self devParseFiles: (('/Users/cyril/marius/selected_notebooks_converted/batch_' , aString) asFileReference allFiles select: [ :f | f extension = 'py' ])
]
{ #category : 'development support' }
FASTPythonImporter class >> devParseFiles: aCollection [
"Command specific to help me develop. this is useful to know the file to parse everything and detect if this raises any error.
We do not save the models to not flood the memory and allow their GC..
I save as last element the time it took to run on the full batch."
<ignoreForCoverage>
| result |
result := OrderedCollection new.
result add: [
aCollection
do: [ :file |
| timeToRun |
timeToRun := [ self parseFile: file ] millisecondsToRun.
result add: file -> timeToRun ]
displayingProgress: [ :file | file pathString ] ] millisecondsToRun.
result inspect
]
{ #category : 'accessing' }
FASTPythonImporter class >> extensions [
"File extensions without the dot that the importer handles"
^ #( 'py' )
]
{ #category : 'parsing' }
FASTPythonImporter class >> parseAndResolve: aString [
| model |
model := self parse: aString.
FASTPythonSSAVisitor resolve: model module.
^ model
]
{ #category : 'parsing' }
FASTPythonImporter class >> parseFileAndResolve: aFileReference [
| model |
model := self parseFile: aFileReference.
FASTPythonSSAVisitor resolve: model module.
^ model
]
{ #category : 'accessing' }
FASTPythonImporter >> tsLanguage [
^ TSLanguage python
]
{ #category : 'accessing' }
FASTPythonImporter >> visitorClass [
^ FASTPythonTreeSitterVisitor
]