FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rethinkdb-java/scripts/astdump.py at v2.4.0 · rethinkdb/rethinkdb-java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
rethinkdb
/
rethinkdb-java
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
9
Star
22
Code
Issues
22
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rethinkdb-java
/
scripts
/
astdump.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
42 lines (34 loc) · 1.22 KB
Breadcrumbs
rethinkdb-java
/
scripts
/
astdump.py
Copy path
File metadata and controls
executable file
·
42 lines (34 loc) · 1.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
'''This is a helper script. It takes in python statements on the
command line and dumps out a json-like representation of the AST
returned by ast.parse(expression, mode='eval').body
It is useful if you're making changes to the convert_java.py script
and want to know what the ast of some python expression looks like.
'''
import
ast
import
json
def
convert_to_dict
(
node
):
if
isinstance
(
node
,
list
):
return
[
convert_to_dict
(
n
)
for
n
in
node
]
elif
isinstance
(
node
,
dict
):
return
{
k
:
convert_to_dict
(
v
)
for
k
,
v
in
node
.
items
()}
elif
isinstance
(
node
,
ast
.
AST
):
nodedict
=
node
.
__dict__
.
copy
()
nodedict
[
'<type>'
]
=
node
.
__class__
.
__name__
return
convert_to_dict
(
nodedict
)
elif
isinstance
(
node
, (
int
,
float
,
str
,
bool
)):
return
node
else
:
return
repr
(
node
)
def
get_astjson
(
expr
,
mode
=
'eval'
):
asta
=
ast
.
parse
(
expr
,
mode
=
mode
).
body
if
isinstance
(
asta
,
list
):
asta
=
asta
[
0
]
converted
=
convert_to_dict
(
asta
)
return
json
.
dumps
(
converted
,
indent
=
4
,
sort_keys
=
True
)
def
ppast
(
expr
,
mode
=
'eval'
):
astjson
=
get_astjson
(
expr
,
mode
=
mode
)
print
(
astjson
)
if
__name__
==
"__main__"
:
import
sys
ppast
(
sys
.
argv
[
1
])
Back
|
FazBrowse Home
|
New Git URL