Skip to content

Commit 409e448

Browse files
committed
Start to use a Customizable importer
1 parent a9c6446 commit 409e448

3 files changed

Lines changed: 42 additions & 16 deletions

File tree

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Class {
1515
{ #category : 'running' }
1616
FASTPythonImporterTest >> parse: aString [
1717

18-
fast := importer parse: '#There is only one comment' withPlatformLineEndings
18+
fast := importer parse: aString withPlatformLineEndings
1919
]
2020

2121
{ #category : 'running' }
@@ -29,8 +29,32 @@ FASTPythonImporterTest >> setUp [
2929
{ #category : 'tests' }
3030
FASTPythonImporterTest >> testFileWithOneComment [
3131

32+
| entity |
3233
self parse: '#There is only one comment'.
3334

3435
self assert: (fast allWithType: FASTPythonModule) size equals: 1.
35-
self assert: (fast allWithType: FASTPythonComment) size equals: 1
36+
entity := (fast allWithType: FASTPythonModule) anyOne.
37+
self assert: entity sourceCode equals: '#There is only one comment'.
38+
39+
self assert: (fast allWithType: FASTPythonComment) size equals: 1.
40+
entity := (fast allWithType: FASTPythonComment) anyOne.
41+
self assert: entity sourceCode equals: '#There is only one comment'
42+
]
43+
44+
{ #category : 'tests' }
45+
FASTPythonImporterTest >> testFileWithTwoComments [
46+
47+
| entity |
48+
self parse: '# Comment 1
49+
50+
# Comment 2'.
51+
52+
self assert: (fast allWithType: FASTPythonModule) size equals: 1.
53+
entity := (fast allWithType: FASTPythonModule) anyOne.
54+
self assert: entity sourceCode equals: '# Comment 1
55+
56+
# Comment 2' withPlatformLineEndings.
57+
58+
self assert: (fast allWithType: FASTPythonComment) size equals: 2.
59+
self assertCollection: ((fast allWithType: FASTPythonComment) collect: #sourceCode as: Array) hasSameElements: { '# Comment 1'. '# Comment 2' }
3660
]

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@ FASTPythonImporter >> deleteTreeSitterParser [
1414
self tsParser delete
1515
]
1616

17-
{ #category : 'parsing' }
18-
FASTPythonImporter >> importToFAST: tsTree usingSourceCode: aString [
19-
20-
| tsLanguage importer |
21-
tsLanguage := TSLanguage python.
22-
importer := TSFASTImporter new.
23-
importer tsLanguage: tsLanguage.
24-
importer languageName: 'Python'.
25-
importer originString: aString.
26-
27-
^ importer import: tsTree
28-
]
29-
3017
{ #category : 'as yet unclassified' }
3118
FASTPythonImporter >> initialiseTreeSitterParser [
3219

@@ -41,7 +28,9 @@ FASTPythonImporter >> parse: aString [
4128
self initialiseTreeSitterParser.
4229

4330
tsTree := self tsParser parseString: aString.
44-
fastTree := self importToFAST: tsTree rootNode usingSourceCode: aString.
31+
fastTree := TSFASTPythonImporter new
32+
originString: aString;
33+
import: tsTree rootNode.
4534

4635
self deleteTreeSitterParser.
4736

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Class {
2+
#name : 'TSFASTPythonImporter',
3+
#superclass : 'TSFASTCustomizableImporter',
4+
#category : 'FAST-Python-Tools',
5+
#package : 'FAST-Python-Tools'
6+
}
7+
8+
{ #category : 'initialization' }
9+
TSFASTPythonImporter >> initialize [
10+
11+
super initialize.
12+
self languageName: 'Python'
13+
]

0 commit comments

Comments
 (0)