Skip to content

Commit

Permalink
Merge pull request #2559 from ruby/ripper
Browse files Browse the repository at this point in the history
Ripper translation
  • Loading branch information
kddnewton committed Mar 6, 2024
2 parents cb7c87d + 5cf5f15 commit 74c3ae0
Show file tree
Hide file tree
Showing 10 changed files with 3,545 additions and 1,127 deletions.
16 changes: 10 additions & 6 deletions bin/prism
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ module Prism
require "benchmark/ips"
require "parser/current"
require "ruby_parser"
require "ripper"

filepath = argv.fetch(0) { File.expand_path("../lib/prism/node.rb", __dir__) }
source = File.read(filepath)

Benchmark.ips do |x|
x.report("prism") { Prism.parse_file(filepath) }
x.report("parser") { Parser::CurrentRuby.parse_file(filepath) }
x.report("Prism::Translation::Parser") { Prism::Translation::Parser.parse_file(filepath) }
x.report("ruby_parser") { RubyParser.new.parse(File.read(filepath), filepath) }
x.report("Prism::Translation::RubyParser") { Prism::Translation::RubyParser.parse_file(filepath) }
x.report("Prism") { Prism.parse(source, filepath: filepath) }
x.report("Ripper::SexpBuilder") { Ripper.sexp_raw(source, filepath) }
x.report("Prism::Translation::Ripper::SexpBuilder") { Prism::Translation::Ripper.sexp_raw(source, filepath) }
x.report("Parser::CurrentRuby") { Parser::CurrentRuby.parse(source, filepath) }
x.report("Prism::Translation::Parser") { Prism::Translation::Parser.parse(source, filepath) }
x.report("RubyParser") { RubyParser.new.parse(source, filepath) }
x.report("Prism::Translation::RubyParser") { Prism::Translation::RubyParser.new.parse(source, filepath) }
x.compare!
end
end
Expand Down Expand Up @@ -247,7 +251,7 @@ module Prism
source, filepath = read_source(argv)

ripper = Ripper.sexp_raw(source)
prism = Prism::Translation::Ripper.sexp_raw(source) rescue :parse_error
prism = Prism::Translation::Ripper.sexp_raw(source)

puts "Ripper:"
pp ripper
Expand Down
7 changes: 1 addition & 6 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ def visit_if_node(node)
end

# 1i
# ^^
def visit_imaginary_node(node)
visit_numeric(node, builder.complex([imaginary_value(node), srange(node.location)]))
end
Expand Down Expand Up @@ -887,9 +888,6 @@ def visit_instance_variable_read_node(node)

# @foo = 1
# ^^^^^^^^
#
# @foo, @bar = 1
# ^^^^ ^^^^
def visit_instance_variable_write_node(node)
builder.assign(
builder.assignable(builder.ivar(token(node.name_loc))),
Expand Down Expand Up @@ -1033,9 +1031,6 @@ def visit_local_variable_read_node(node)

# foo = 1
# ^^^^^^^
#
# foo, bar = 1
# ^^^ ^^^
def visit_local_variable_write_node(node)
builder.assign(
builder.assignable(builder.ident(token(node.name_loc))),
Expand Down
Loading

0 comments on commit 74c3ae0

Please sign in to comment.