[ruby/prism] Resync RBI and test it in CI
https://github.com/ruby/prism/commit/4ef4032774
This commit is contained in:
parent
5891c70b38
commit
cd8d1018bb
@ -94,6 +94,12 @@ require_relative "prism/parse_result/newlines"
|
|||||||
# module that uses FFI to call into the library.
|
# module that uses FFI to call into the library.
|
||||||
if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"]
|
if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"]
|
||||||
require "prism/prism"
|
require "prism/prism"
|
||||||
|
|
||||||
|
# Using a C extension is the default backend for the parser.
|
||||||
|
Prism::BACKEND = :CEXT
|
||||||
else
|
else
|
||||||
require_relative "prism/ffi"
|
require_relative "prism/ffi"
|
||||||
|
|
||||||
|
# On platforms that don't support C extensions, we use FFI.
|
||||||
|
Prism::BACKEND = :FFI
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
# typed: ignore
|
||||||
|
|
||||||
# This file is responsible for mirroring the API provided by the C extension by
|
# This file is responsible for mirroring the API provided by the C extension by
|
||||||
# using FFI to call into the shared library.
|
# using FFI to call into the shared library.
|
||||||
@ -7,8 +8,6 @@ require "rbconfig"
|
|||||||
require "ffi"
|
require "ffi"
|
||||||
|
|
||||||
module Prism
|
module Prism
|
||||||
BACKEND = :FFI
|
|
||||||
|
|
||||||
module LibRubyParser # :nodoc:
|
module LibRubyParser # :nodoc:
|
||||||
extend FFI::Library
|
extend FFI::Library
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
# typed: ignore
|
||||||
|
|
||||||
module Prism
|
module Prism
|
||||||
# A parser for the pack template language.
|
# A parser for the pack template language.
|
||||||
|
@ -136,7 +136,17 @@ Gem::Specification.new do |spec|
|
|||||||
"sig/prism/serialize.rbs",
|
"sig/prism/serialize.rbs",
|
||||||
"sig/prism/visitor.rbs",
|
"sig/prism/visitor.rbs",
|
||||||
"rbi/prism.rbi",
|
"rbi/prism.rbi",
|
||||||
"rbi/prism_static.rbi"
|
"rbi/prism/compiler.rbi",
|
||||||
|
"rbi/prism/desugar_compiler.rbi",
|
||||||
|
"rbi/prism/mutation_compiler.rbi",
|
||||||
|
"rbi/prism/node_ext.rbi",
|
||||||
|
"rbi/prism/node.rbi",
|
||||||
|
"rbi/prism/parse_result.rbi",
|
||||||
|
"rbi/prism/translation/parser/compiler.rbi",
|
||||||
|
"rbi/prism/translation/ripper.rbi",
|
||||||
|
"rbi/prism/translation/ripper/ripper_compiler.rbi",
|
||||||
|
"rbi/prism/translation/ruby_parser.rbi",
|
||||||
|
"rbi/prism/visitor.rbi"
|
||||||
]
|
]
|
||||||
|
|
||||||
spec.extensions = ["ext/prism/extconf.rb"]
|
spec.extensions = ["ext/prism/extconf.rb"]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
# typed: ignore
|
||||||
|
|
||||||
require "parser"
|
require "parser"
|
||||||
require "rubocop"
|
require "rubocop"
|
||||||
|
@ -1254,13 +1254,6 @@ Init_prism(void) {
|
|||||||
*/
|
*/
|
||||||
rb_define_const(rb_cPrism, "VERSION", rb_str_new2(EXPECTED_PRISM_VERSION));
|
rb_define_const(rb_cPrism, "VERSION", rb_str_new2(EXPECTED_PRISM_VERSION));
|
||||||
|
|
||||||
/**
|
|
||||||
* The backend of the parser that prism is using to parse Ruby code. This
|
|
||||||
* can be either :CEXT or :FFI. On runtimes that support C extensions, we
|
|
||||||
* default to :CEXT. Otherwise we use :FFI.
|
|
||||||
*/
|
|
||||||
rb_define_const(rb_cPrism, "BACKEND", ID2SYM(rb_intern("CEXT")));
|
|
||||||
|
|
||||||
// First, the functions that have to do with lexing and parsing.
|
// First, the functions that have to do with lexing and parsing.
|
||||||
rb_define_singleton_method(rb_cPrism, "dump", dump, -1);
|
rb_define_singleton_method(rb_cPrism, "dump", dump, -1);
|
||||||
rb_define_singleton_method(rb_cPrism, "dump_file", dump_file, -1);
|
rb_define_singleton_method(rb_cPrism, "dump_file", dump_file, -1);
|
||||||
|
@ -91,7 +91,6 @@ module Prism
|
|||||||
case load_varuint
|
case load_varuint
|
||||||
when 0 then InlineComment.new(load_location)
|
when 0 then InlineComment.new(load_location)
|
||||||
when 1 then EmbDocComment.new(load_location)
|
when 1 then EmbDocComment.new(load_location)
|
||||||
when 2 then DATAComment.new(load_location)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# typed: false
|
||||||
|
|
||||||
require "erb"
|
require "erb"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
@ -28,7 +29,7 @@ module Prism
|
|||||||
end
|
end
|
||||||
|
|
||||||
# A comment attached to a field or node.
|
# A comment attached to a field or node.
|
||||||
class Comment
|
class ConfigComment
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
|
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@ -40,7 +41,7 @@ module Prism
|
|||||||
end
|
end
|
||||||
|
|
||||||
def each_java_line(&block)
|
def each_java_line(&block)
|
||||||
Comment.new(JavaDoc.escape(value)).each_line(&block)
|
ConfigComment.new(JavaDoc.escape(value)).each_line(&block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -56,11 +57,11 @@ module Prism
|
|||||||
end
|
end
|
||||||
|
|
||||||
def each_comment_line(&block)
|
def each_comment_line(&block)
|
||||||
Comment.new(comment).each_line(&block) if comment
|
ConfigComment.new(comment).each_line(&block) if comment
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_comment_java_line(&block)
|
def each_comment_java_line(&block)
|
||||||
Comment.new(comment).each_java_line(&block) if comment
|
ConfigComment.new(comment).each_java_line(&block) if comment
|
||||||
end
|
end
|
||||||
|
|
||||||
def semantic_field?
|
def semantic_field?
|
||||||
@ -122,7 +123,13 @@ module Prism
|
|||||||
end
|
end
|
||||||
|
|
||||||
def rbi_class
|
def rbi_class
|
||||||
"Prism::#{ruby_type}"
|
if specific_kind
|
||||||
|
"Prism::#{specific_kind}"
|
||||||
|
elsif union_kind
|
||||||
|
"T.any(#{union_kind.map { |kind| "Prism::#{kind}" }.join(", ")})"
|
||||||
|
else
|
||||||
|
"Prism::Node"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_field_kind
|
def check_field_kind
|
||||||
@ -148,7 +155,13 @@ module Prism
|
|||||||
end
|
end
|
||||||
|
|
||||||
def rbi_class
|
def rbi_class
|
||||||
"T.nilable(Prism::#{ruby_type})"
|
if specific_kind
|
||||||
|
"T.nilable(Prism::#{specific_kind})"
|
||||||
|
elsif union_kind
|
||||||
|
"T.nilable(T.any(#{union_kind.map { |kind| "Prism::#{kind}" }.join(", ")}))"
|
||||||
|
else
|
||||||
|
"T.nilable(Prism::Node)"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_field_kind
|
def check_field_kind
|
||||||
@ -174,7 +187,13 @@ module Prism
|
|||||||
end
|
end
|
||||||
|
|
||||||
def rbi_class
|
def rbi_class
|
||||||
"T::Array[Prism::#{ruby_type}]"
|
if specific_kind
|
||||||
|
"T::Array[Prism::#{specific_kind}]"
|
||||||
|
elsif union_kind
|
||||||
|
"T::Array[T.any(#{union_kind.map { |kind| "Prism::#{kind}" }.join(", ")})]"
|
||||||
|
else
|
||||||
|
"T::Array[Prism::Node]"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def java_type
|
def java_type
|
||||||
@ -406,11 +425,11 @@ module Prism
|
|||||||
end
|
end
|
||||||
|
|
||||||
def each_comment_line(&block)
|
def each_comment_line(&block)
|
||||||
Comment.new(comment).each_line(&block)
|
ConfigComment.new(comment).each_line(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_comment_java_line(&block)
|
def each_comment_java_line(&block)
|
||||||
Comment.new(comment).each_java_line(&block)
|
ConfigComment.new(comment).each_java_line(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def semantic_fields
|
def semantic_fields
|
||||||
@ -494,6 +513,7 @@ module Prism
|
|||||||
when ".rb"
|
when ".rb"
|
||||||
<<~HEADING
|
<<~HEADING
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
This file is generated by the templates/template.rb script and should not be
|
This file is generated by the templates/template.rb script and should not be
|
||||||
modified manually. See #{filepath}
|
modified manually. See #{filepath}
|
||||||
@ -510,11 +530,14 @@ module Prism
|
|||||||
HEADING
|
HEADING
|
||||||
when ".rbi"
|
when ".rbi"
|
||||||
<<~HEADING
|
<<~HEADING
|
||||||
|
# typed: strict
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
This file is generated by the templates/template.rb script and should not be
|
This file is generated by the templates/template.rb script and should not be
|
||||||
modified manually. See #{filepath}
|
modified manually. See #{filepath}
|
||||||
if you are looking to modify the template
|
if you are looking to modify the template
|
||||||
=end
|
=end
|
||||||
|
|
||||||
HEADING
|
HEADING
|
||||||
else
|
else
|
||||||
<<~HEADING
|
<<~HEADING
|
||||||
@ -525,6 +548,7 @@ module Prism
|
|||||||
/* if you are looking to modify the */
|
/* if you are looking to modify the */
|
||||||
/* template */
|
/* template */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
HEADING
|
HEADING
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -598,7 +622,8 @@ module Prism
|
|||||||
"src/prettyprint.c",
|
"src/prettyprint.c",
|
||||||
"src/serialize.c",
|
"src/serialize.c",
|
||||||
"src/token_type.c",
|
"src/token_type.c",
|
||||||
"rbi/prism.rbi",
|
"rbi/prism/node.rbi",
|
||||||
|
"rbi/prism/visitor.rbi",
|
||||||
"sig/prism.rbs",
|
"sig/prism.rbs",
|
||||||
"sig/prism/dsl.rbs",
|
"sig/prism/dsl.rbs",
|
||||||
"sig/prism/mutation_compiler.rbs",
|
"sig/prism/mutation_compiler.rbs",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
# typed: ignore
|
||||||
|
|
||||||
require_relative "test_helper"
|
require_relative "test_helper"
|
||||||
|
|
||||||
|
@ -3,15 +3,13 @@
|
|||||||
require_relative "test_helper"
|
require_relative "test_helper"
|
||||||
|
|
||||||
module Prism
|
module Prism
|
||||||
class RipperTest < TestCase
|
class RipperTestCase < TestCase
|
||||||
|
private
|
||||||
|
|
||||||
def truffleruby?
|
def truffleruby?
|
||||||
RUBY_ENGINE == "truffleruby"
|
RUBY_ENGINE == "truffleruby"
|
||||||
end
|
end
|
||||||
|
|
||||||
def windows?
|
|
||||||
Gem.win_platform?
|
|
||||||
end
|
|
||||||
|
|
||||||
# Ripper produces certain ambiguous structures. For instance, it often
|
# Ripper produces certain ambiguous structures. For instance, it often
|
||||||
# adds an :args_add_block with "false" as the block meaning there is
|
# adds an :args_add_block with "false" as the block meaning there is
|
||||||
# no block call. It can be hard to tell which of multiple equivalent
|
# no block call. It can be hard to tell which of multiple equivalent
|
||||||
@ -44,10 +42,9 @@ module Prism
|
|||||||
actual = normalized_sexp(actual)
|
actual = normalized_sexp(actual)
|
||||||
assert_equal expected, actual, "Expected Ripper and Prism to give equivalent output for #{path}!"
|
assert_equal expected, actual, "Expected Ripper and Prism to give equivalent output for #{path}!"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class RipperShortSourceTest < RipperTest
|
class RipperShortSourceTest < RipperTestCase
|
||||||
def test_binary
|
def test_binary
|
||||||
assert_equivalent("1 + 2")
|
assert_equivalent("1 + 2")
|
||||||
assert_equivalent("3 - 4 * 5")
|
assert_equivalent("3 - 4 * 5")
|
||||||
@ -258,13 +255,16 @@ module Prism
|
|||||||
assert_equivalent("alias :'' :foo")
|
assert_equivalent("alias :'' :foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Translation::Ripper
|
||||||
|
RUBY_KEYWORDS = Translation.const_get(:RipperCompiler)::RUBY_KEYWORDS
|
||||||
|
|
||||||
# This is *exactly* the kind of thing where Ripper would have a weird
|
# This is *exactly* the kind of thing where Ripper would have a weird
|
||||||
# special case we didn't handle correctly. We're still testing with
|
# special case we didn't handle correctly. We're still testing with
|
||||||
# a leading colon since putting random keywords there will often get
|
# a leading colon since putting random keywords there will often get
|
||||||
# parse errors. Mostly we want to know that Ripper will use :@kw
|
# parse errors. Mostly we want to know that Ripper will use :@kw
|
||||||
# instead of :@ident for the lexer symbol for all of these.
|
# instead of :@ident for the lexer symbol for all of these.
|
||||||
def test_keyword_aliases
|
def test_keyword_aliases
|
||||||
Prism::Translation::Ripper::RUBY_KEYWORDS.each do |keyword|
|
RUBY_KEYWORDS.each do |keyword|
|
||||||
assert_equivalent("alias :foo :#{keyword}")
|
assert_equivalent("alias :foo :#{keyword}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -276,7 +276,7 @@ module Prism
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RipperFixturesTest < RipperTest
|
class RipperFixturesTest < RipperTestCase
|
||||||
#base = File.join(__dir__, "fixtures")
|
#base = File.join(__dir__, "fixtures")
|
||||||
#relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base]
|
#relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base]
|
||||||
relatives = [
|
relatives = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user