Skip to content

Commit 893badf

Browse files
committed
extract the parser separately in the python import time feenkcom/gtoolkit#4607
1 parent 0572f4f commit 893badf

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/GToolkit4Python/GtPyImportTimePackage.class.st

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,11 @@ import time: 19 | 19 | marshal
2727
import time: 131 | 131 | posix
2828
import time: 363 | 590 | _frozen_importlib_external
2929
import time: 450 | 450 | time
30-
..."
31-
| lineParser root stack lines |
32-
lines := aString lines allButFirst reversed select: [:each | each beginsWith: 'import time'].
33-
lineParser := ('import time:' asPParser trim
34-
, #digit asPParser plus flatten trim , '|' asPParser trim
35-
, #digit asPParser plus flatten trim , '|' asPParser , #space asPParser
36-
, #space asPParser star , #endOfInput asPParser negate plus flatten)
37-
==> [ :t |
38-
GtPyImportTimePackage new
39-
localTime: (t at: 2) asNumber;
40-
cumulativeTime: (t at: 4) asNumber;
41-
nesting: (t at: 7) size / 2;
42-
name: (t at: 8) ].
30+
..."
31+
32+
| root stack lines |
33+
lines := aString lines allButFirst reversed
34+
select: [ :each | each beginsWith: 'import time' ].
4335
root := GtPyImportTimePackage new
4436
localTime: 0;
4537
cumulativeTime: -1;
@@ -50,13 +42,27 @@ import time: 450 | 450 | time
5042
lines
5143
do: [ :each |
5244
| newPackage |
53-
newPackage := lineParser parse: each.
45+
newPackage := self lineParser parse: each.
5446
[ newPackage nesting <= stack top nesting ] whileTrue: [ stack pop ].
5547
stack top addChild: newPackage.
5648
stack push: newPackage ].
5749
^ root
5850
]
5951

52+
{ #category : #'as yet unclassified' }
53+
GtPyImportTimePackage class >> lineParser [
54+
^ ('import time:' asPParser trim , #digit asPParser plus flatten trim
55+
, '|' asPParser trim , #digit asPParser plus flatten trim , '|' asPParser
56+
, #space asPParser , #space asPParser star
57+
, #endOfInput asPParser negate plus flatten)
58+
==> [ :t |
59+
GtPyImportTimePackage new
60+
localTime: (t at: 2) asNumber;
61+
cumulativeTime: (t at: 4) asNumber;
62+
nesting: (t at: 7) size / 2;
63+
name: (t at: 8) ]
64+
]
65+
6066
{ #category : #'as yet unclassified' }
6167
GtPyImportTimePackage >> addChild: aPyImportTimePackage [
6268
children add: aPyImportTimePackage

0 commit comments

Comments
 (0)