diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-11-03 13:36:28 -0400 |
---|---|---|
committer | Kevin Newton <kddnewton@gmail.com> | 2023-11-14 16:22:02 -0500 |
commit | bc84334af7e6100f0ede678704f5b80fcaabc0c9 (patch) | |
tree | 691a33e2b863da585ac60ace432a4c8c7ff8a584 /bin | |
parent | db8803d583c31767a2f6771ecdf929bf5ee6c278 (diff) |
[ruby/prism] Add the ability to convert nodes to dot
https://github.com/ruby/prism/commit/3e4b4fb947
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/dot | 21 |
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 +) |