File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 11import parso
22from parso .python .tokenize import tokenize
3- from parso .python .token import tok_name
43import json
5- import sys
4+ import sys
65
76file = open (sys .argv [1 ],'r' )
87file_content = file .read ()
98
109tokens = []
1110
1211for token in tokenize (file_content , version_info = (3 ,6 )):
13- tmp = dict ()
14- tmp ["line" ]= (token .start_pos )[0 ];
15- tmp ["char" ]= ((token .start_pos )[1 ])+ 1 ;
16- tmp ["type" ]= str (tok_name [token .type ])
17- tmp ["value" ]= str (token .string )
18- tokens .append (tmp )
12+ if (str (token .string ) != "" ):
13+ tmp = dict ()
14+ tmp ["line" ]= (token .start_pos )[0 ];
15+ tmp ["char" ]= ((token .start_pos )[1 ])+ 1 ;
16+ tmp ["type" ]= ((str (token .type ))[10 :]).strip (")" )
17+ tmp ["value" ]= str (token .string )
18+ tokens .append (tmp )
1919
2020print ( json .dumps (tokens , indent = 4 , sort_keys = True ) )
21-
You can’t perform that action at this time.
0 commit comments