[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.
|
||||
if RUBY_ENGINE == "ruby" and !ENV["PRISM_FFI_BACKEND"]
|
||||
require "prism/prism"
|
||||
|
||||
# Using a C extension is the default backend for the parser.
|
||||
Prism::BACKEND = :CEXT
|
||||
else
|
||||
require_relative "prism/ffi"
|
||||
|
||||
# On platforms that don't support C extensions, we use FFI.
|
||||
Prism::BACKEND = :FFI
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
# typed: ignore
|
||||
|
||||
# This file is responsible for mirroring the API provided by the C extension by
|
||||
# using FFI to call into the shared library.
|
||||
@ -7,8 +8,6 @@ require "rbconfig"
|
||||
require "ffi"
|
||||
|
||||
module Prism
|
||||
BACKEND = :FFI
|
||||
|
||||
module LibRubyParser # :nodoc:
|
||||
extend FFI::Library
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
# typed: ignore
|
||||
|
||||
module Prism
|
||||
# A parser for the pack template language.
|
||||
|
@ -136,7 +136,17 @@ Gem::Specification.new do |spec|
|
||||
"sig/prism/serialize.rbs",
|
||||
"sig/prism/visitor.rbs",
|
||||
"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"]
|
||||
|
@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
# typed: ignore
|
||||
|
||||
require "parser"
|
||||
require "rubocop"
|
||||
|
@ -1254,13 +1254,6 @@ Init_prism(void) {
|
||||
*/
|
||||
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.
|
||||
rb_define_singleton_method(rb_cPrism, "dump", dump, -1);
|
||||
rb_define_singleton_method(rb_cPrism, "dump_file", dump_file, -1);
|
||||
|
@ -91,7 +91,6 @@ module Prism
|
||||
case load_varuint
|
||||
when 0 then InlineComment.new(load_location)
|
||||
when 1 then EmbDocComment.new(load_location)
|
||||
when 2 then DATAComment.new(load_location)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env ruby
|
||||
# typed: false
|
||||
|
||||
require "erb"
|
||||
require "fileutils"
|
||||
@ -28,7 +29,7 @@ module Prism
|
||||
end
|
||||
|
||||
# A comment attached to a field or node.
|
||||
class Comment
|
||||
class ConfigComment
|
||||
attr_reader :value
|
||||
|
||||
def initialize(value)
|
||||
@ -40,7 +41,7 @@ module Prism
|
||||
end
|
||||
|
||||
def each_java_line(&block)
|
||||
Comment.new(JavaDoc.escape(value)).each_line(&block)
|
||||
ConfigComment.new(JavaDoc.escape(value)).each_line(&block)
|
||||
end
|
||||
end
|
||||
|
||||
@ -56,11 +57,11 @@ module Prism
|
||||
end
|
||||
|
||||
def each_comment_line(&block)
|
||||
Comment.new(comment).each_line(&block) if comment
|
||||
ConfigComment.new(comment).each_line(&block) if comment
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def semantic_field?
|
||||
@ -122,7 +123,13 @@ module Prism
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def check_field_kind
|
||||
@ -148,7 +155,13 @@ module Prism
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def check_field_kind
|
||||
@ -174,7 +187,13 @@ module Prism
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def java_type
|
||||
@ -406,11 +425,11 @@ module Prism
|
||||
end
|
||||
|
||||
def each_comment_line(&block)
|
||||
Comment.new(comment).each_line(&block)
|
||||
ConfigComment.new(comment).each_line(&block)
|
||||
end
|
||||
|
||||
def each_comment_java_line(&block)
|
||||
Comment.new(comment).each_java_line(&block)
|
||||
ConfigComment.new(comment).each_java_line(&block)
|
||||
end
|
||||
|
||||
def semantic_fields
|
||||
@ -494,6 +513,7 @@ module Prism
|
||||
when ".rb"
|
||||
<<~HEADING
|
||||
# frozen_string_literal: true
|
||||
|
||||
=begin
|
||||
This file is generated by the templates/template.rb script and should not be
|
||||
modified manually. See #{filepath}
|
||||
@ -509,13 +529,16 @@ module Prism
|
||||
|
||||
HEADING
|
||||
when ".rbi"
|
||||
<<~HEADING
|
||||
=begin
|
||||
This file is generated by the templates/template.rb script and should not be
|
||||
modified manually. See #{filepath}
|
||||
if you are looking to modify the template
|
||||
=end
|
||||
HEADING
|
||||
<<~HEADING
|
||||
# typed: strict
|
||||
|
||||
=begin
|
||||
This file is generated by the templates/template.rb script and should not be
|
||||
modified manually. See #{filepath}
|
||||
if you are looking to modify the template
|
||||
=end
|
||||
|
||||
HEADING
|
||||
else
|
||||
<<~HEADING
|
||||
/******************************************************************************/
|
||||
@ -525,6 +548,7 @@ module Prism
|
||||
/* if you are looking to modify the */
|
||||
/* template */
|
||||
/******************************************************************************/
|
||||
|
||||
HEADING
|
||||
end
|
||||
|
||||
@ -598,7 +622,8 @@ module Prism
|
||||
"src/prettyprint.c",
|
||||
"src/serialize.c",
|
||||
"src/token_type.c",
|
||||
"rbi/prism.rbi",
|
||||
"rbi/prism/node.rbi",
|
||||
"rbi/prism/visitor.rbi",
|
||||
"sig/prism.rbs",
|
||||
"sig/prism/dsl.rbs",
|
||||
"sig/prism/mutation_compiler.rbs",
|
||||
|
@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
# typed: ignore
|
||||
|
||||
require_relative "test_helper"
|
||||
|
||||
|
@ -3,15 +3,13 @@
|
||||
require_relative "test_helper"
|
||||
|
||||
module Prism
|
||||
class RipperTest < TestCase
|
||||
class RipperTestCase < TestCase
|
||||
private
|
||||
|
||||
def truffleruby?
|
||||
RUBY_ENGINE == "truffleruby"
|
||||
end
|
||||
|
||||
def windows?
|
||||
Gem.win_platform?
|
||||
end
|
||||
|
||||
# Ripper produces certain ambiguous structures. For instance, it often
|
||||
# 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
|
||||
@ -44,10 +42,9 @@ module Prism
|
||||
actual = normalized_sexp(actual)
|
||||
assert_equal expected, actual, "Expected Ripper and Prism to give equivalent output for #{path}!"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class RipperShortSourceTest < RipperTest
|
||||
class RipperShortSourceTest < RipperTestCase
|
||||
def test_binary
|
||||
assert_equivalent("1 + 2")
|
||||
assert_equivalent("3 - 4 * 5")
|
||||
@ -258,13 +255,16 @@ module Prism
|
||||
assert_equivalent("alias :'' :foo")
|
||||
end
|
||||
|
||||
Translation::Ripper
|
||||
RUBY_KEYWORDS = Translation.const_get(:RipperCompiler)::RUBY_KEYWORDS
|
||||
|
||||
# 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
|
||||
# a leading colon since putting random keywords there will often get
|
||||
# parse errors. Mostly we want to know that Ripper will use :@kw
|
||||
# instead of :@ident for the lexer symbol for all of these.
|
||||
def test_keyword_aliases
|
||||
Prism::Translation::Ripper::RUBY_KEYWORDS.each do |keyword|
|
||||
RUBY_KEYWORDS.each do |keyword|
|
||||
assert_equivalent("alias :foo :#{keyword}")
|
||||
end
|
||||
end
|
||||
@ -276,7 +276,7 @@ module Prism
|
||||
end
|
||||
end
|
||||
|
||||
class RipperFixturesTest < RipperTest
|
||||
class RipperFixturesTest < RipperTestCase
|
||||
#base = File.join(__dir__, "fixtures")
|
||||
#relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base]
|
||||
relatives = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user