FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/extractor/tsg-python/tsg_to_dot.py at codeql-cli-2.19.2 · github/codeql · GitHub
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10.1k
Code
Issues
1k
Pull requests
468
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
python
/
extractor
/
tsg-python
/
tsg_to_dot.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (51 loc) · 1.93 KB
Breadcrumbs
codeql
/
python
/
extractor
/
tsg-python
/
tsg_to_dot.py
Copy path
File metadata and controls
60 lines (51 loc) · 1.93 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Convert output of tree-sitter-graph to dot format.
import
sys
import
re
# regular expression to match a node
node_re
=
re
.
compile
(
r"node (?P<id>\d+)"
)
# regular expression to match an edge
edge_re
=
re
.
compile
(
r"edge (?P<from>\d+) -> (?P<to>\d+)"
)
# regular expression to match a property
prop_re
=
re
.
compile
(
r"\s+(?P<key>\w+): (?P<value>.*)"
)
# regular expression to match a link: "[graph node n]"
link_re
=
re
.
compile
(
r"\[graph node (?P<id>\d+)\]"
)
with
open
(
sys
.
argv
[
1
],
'r'
)
as
f
,
open
(
sys
.
argv
[
2
],
'w'
)
as
out
:
out
.
write
(
"digraph G {
\n
"
)
label
=
[]
inside
=
False
node_id
=
0
links
=
{}
for
line
in
f
:
m
=
node_re
.
match
(
line
)
if
m
:
if
inside
:
out
.
write
(
'
\\
n'
.
join
(
label
)
+
"
\"
];
\n
"
)
for
k
,
v
in
links
.
items
():
out
.
write
(
"{} -> {} [label=
\"
{}
\"
];
\n
"
.
format
(
node_id
,
v
,
k
))
out
.
write
(
"{id} [label=
\"
"
.
format
(
**
m
.
groupdict
()))
label
=
[
"id={id}"
.
format
(
**
m
.
groupdict
())]
inside
=
True
node_id
=
m
.
group
(
'id'
)
links
=
{}
m
=
edge_re
.
match
(
line
)
if
m
:
if
inside
:
out
.
write
(
'
\\
n'
.
join
(
label
)
+
"
\"
];
\n
"
)
for
k
,
v
in
links
.
items
():
out
.
write
(
"{} -> {} [label=
\"
{}
\"
];
\n
"
.
format
(
node_id
,
v
,
k
))
out
.
write
(
"{from} -> {to} [label=
\"
"
.
format
(
**
m
.
groupdict
()))
label
=
[]
inside
=
True
node_id
=
0
links
=
{}
m
=
prop_re
.
match
(
line
)
if
m
:
# escape quotes in value
label
.
append
(
"{key}={value}"
.
format
(
**
m
.
groupdict
()).
replace
(
'"'
,
'
\\
"'
).
replace
(
'
\\
\\
"'
,
''
))
l
=
link_re
.
match
(
m
.
group
(
'value'
))
if
l
:
links
[
m
.
group
(
'key'
)]
=
l
.
group
(
'id'
)
out
.
write
(
'
\\
n'
.
join
(
label
)
+
"
\"
];
\n
"
)
for
k
,
v
in
links
.
items
():
out
.
write
(
"{} -> {} [label=
\"
{}
\"
];
\n
"
.
format
(
node_id
,
v
,
k
))
out
.
write
(
"}
\n
"
)
Back
|
FazBrowse Home
|
New Git URL