aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-11-03 13:36:28 -0400
committerKevin Newton <kddnewton@gmail.com>2023-11-14 16:22:02 -0500
commitbc84334af7e6100f0ede678704f5b80fcaabc0c9 (patch)
tree691a33e2b863da585ac60ace432a4c8c7ff8a584 /bin
parentdb8803d583c31767a2f6771ecdf929bf5ee6c278 (diff)
downloadruby-bc84334af7e6100f0ede678704f5b80fcaabc0c9.tar.gz
[ruby/prism] Add the ability to convert nodes to dot
https://github.com/ruby/prism/commit/3e4b4fb947
Diffstat (limited to 'bin')
-rwxr-xr-xbin/dot21
1 files changed, 21 insertions, 0 deletions
diff --git a/bin/dot b/bin/dot
new file mode 100755
index 0000000000..343d00e31e
--- /dev/null
+++ b/bin/dot
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+$:.unshift(File.expand_path("../lib", __dir__))
+require "prism"
+
+result =
+ if ARGV[0] == "-e"
+ Prism.parse(ARGV[1])
+ else
+ Prism.parse_file(ARGV[0] || "test.rb")
+ end
+
+File.write(
+ "out.svg",
+ IO.popen("dot -Tsvg", "w+") do |file|
+ file.write(result.value.to_dot)
+ file.close_write
+ file.read
+ end
+)