Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev-only CLI #2378

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions bin/console

This file was deleted.

34 changes: 0 additions & 34 deletions bin/dot

This file was deleted.

117 changes: 0 additions & 117 deletions bin/encodings

This file was deleted.

2 changes: 0 additions & 2 deletions bin/insns

This file was deleted.

62 changes: 2 additions & 60 deletions bin/lex
Original file line number Diff line number Diff line change
@@ -1,61 +1,3 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#!/bin/sh

# Usage:
# bin/lex # defaults to test.rb
# bin/lex <filename>
# bin/lex -e "<source-code>"

$:.unshift(File.expand_path("../lib", __dir__))
require "ripper"
require "prism"

if ARGV[0] == "-e"
source = ARGV[1]
else
filepath = ARGV.first || "test.rb"
source = File.read(filepath)
end

pattern = "%-70s %-70s %-70s"

ripper =
begin
Prism.lex_ripper(source)
rescue ArgumentError, SyntaxError
# If Ripper raises a syntax error, we want to continue as if it didn't
# return any tokens at all. prism won't raise a syntax error, so it's nicer
# to still be able to see the tokens that prism generated.
[]
end

prism = Prism.lex_compat(source, filepath: filepath)
prism_new = Prism.lex(source, filepath: filepath)
if prism.errors.any?
puts "Errors lexing:"
prism.errors.map do |error|
print "- [#{error.location.start_line},#{error.location.start_column}-"
print "#{error.location.end_line},#{error.location.end_column}] "
puts "\e[1;31m#{error.message}\e[0m"
end
puts "\n"
end

puts pattern % ["Ripper lex", "Prism compat lex", "Prism Lex"]
puts pattern % ["-" * 70, "-" * 70, "-" * 70]

prism_value = prism.value
prism_new_value = prism_new.value

[prism_value.length, ripper.length, prism_new_value.length].max.times do |index|
left = ripper[index]
right = prism_value[index]
new = prism_new_value[index]

color = left == right ? "38;5;102" : "1;31"

if ENV["VERBOSE"] || (left != right)
new_value = [new[0].type, [new[0].location.start_offset, new[0].location.length]] if new
puts "\033[#{color}m#{pattern}\033[0m" % [left.inspect, right.inspect, new_value.inspect]
end
end
exec bin/prism lex "$@"
13 changes: 0 additions & 13 deletions bin/locals

This file was deleted.

34 changes: 0 additions & 34 deletions bin/memsize

This file was deleted.

40 changes: 2 additions & 38 deletions bin/parse
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
#!/bin/sh

# Usage:
# bin/parse # defaults to test.rb
# bin/parse <filename>
# bin/parse -e "<source-code>"

$:.unshift(File.expand_path("../lib", __dir__))
require "prism"

if ARGV[0] == "-e"
result = Prism.parse(ARGV[1])
else
result = Prism.parse_file(ARGV[0] || "test.rb")
end

result.mark_newlines! if ENV["MARK_NEWLINES"]

value = result.value
value = value.accept(Prism::DesugarCompiler.new) if ENV["DESUGAR"]

parts = {}
parts["Comments"] = result.comments if result.comments.any?
parts["Magic comments"] = result.magic_comments if result.magic_comments.any?
parts["Warnings"] = result.warnings if result.warnings.any?
parts["Errors"] = result.errors if result.errors.any?
parts["DATA"] = result.data_loc if result.data_loc

if parts.empty?
puts value.inspect
else
parts["AST"] = value
parts.each_with_index do |(key, value), index|
puts if index > 0
puts "#{key}:"
pp value
end
end
exec bin/prism parse "$@"
16 changes: 0 additions & 16 deletions bin/parser

This file was deleted.

Loading
Loading