From bc84334af7e6100f0ede678704f5b80fcaabc0c9 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 3 Nov 2023 13:36:28 -0400 Subject: [ruby/prism] Add the ability to convert nodes to dot https://github.com/ruby/prism/commit/3e4b4fb947 --- bin/dot | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 bin/dot 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 +) -- cgit v1.2.3