diff options
author | Kevin Newton <[email protected]> | 2024-04-17 11:28:52 -0400 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2024-04-17 13:54:29 -0400 |
commit | d186eb36a4abbbefa026ea5630a1b59bb668ef0f (patch) | |
tree | b502ce29121776aefcead8a7a103e6e8f50f41eb /lib | |
parent | ee6e591b6afbe765b2b1a612d8a7bdfc7cbc606c (diff) |
[ruby/prism] Add a reflection API for determining the fields of a node
https://github.com/ruby/prism/commit/f3f9950a74
Diffstat (limited to 'lib')
-rw-r--r-- | lib/prism.rb | 17 | ||||
-rw-r--r-- | lib/prism/ffi.rb | 10 | ||||
-rw-r--r-- | lib/prism/prism.gemspec | 3 |
3 files changed, 14 insertions, 16 deletions
diff --git a/lib/prism.rb b/lib/prism.rb index 23a72fa49a..c512cb4015 100644 --- a/lib/prism.rb +++ b/lib/prism.rb @@ -24,6 +24,7 @@ module Prism autoload :NodeInspector, "prism/node_inspector" autoload :Pack, "prism/pack" autoload :Pattern, "prism/pattern" + autoload :Reflection, "prism/reflection" autoload :Serialize, "prism/serialize" autoload :Translation, "prism/translation" autoload :Visitor, "prism/visitor" @@ -64,22 +65,6 @@ module Prism def self.load(source, serialized) Serialize.load(source, serialized) end - - # :call-seq: - # Prism::parse_failure?(source, **options) -> bool - # - # Returns true if the source parses with errors. - def self.parse_failure?(source, **options) - !parse_success?(source, **options) - end - - # :call-seq: - # Prism::parse_file_failure?(filepath, **options) -> bool - # - # Returns true if the file at filepath parses with errors. - def self.parse_file_failure?(filepath, **options) - !parse_file_success?(filepath, **options) - end end require_relative "prism/node" diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb index 0a064a5c94..1fd053f902 100644 --- a/lib/prism/ffi.rb +++ b/lib/prism/ffi.rb @@ -286,12 +286,22 @@ module Prism LibRubyParser::PrismString.with_string(code) { |string| parse_file_success_common(string, options) } end + # Mirror the Prism.parse_failure? API by using the serialization API. + def parse_failure?(code, **options) + !parse_success?(code, **options) + end + # Mirror the Prism.parse_file_success? API by using the serialization API. def parse_file_success?(filepath, **options) options[:filepath] = filepath LibRubyParser::PrismString.with_file(filepath) { |string| parse_file_success_common(string, options) } end + # Mirror the Prism.parse_file_failure? API by using the serialization API. + def parse_file_failure?(filepath, **options) + !parse_file_success?(filepath, **options) + end + private def dump_common(string, options) # :nodoc: diff --git a/lib/prism/prism.gemspec b/lib/prism/prism.gemspec index f4be1b36bb..c0f3db5594 100644 --- a/lib/prism/prism.gemspec +++ b/lib/prism/prism.gemspec @@ -87,6 +87,7 @@ Gem::Specification.new do |spec| "lib/prism/parse_result/newlines.rb", "lib/prism/pattern.rb", "lib/prism/polyfill/string.rb", + "lib/prism/reflection.rb", "lib/prism/serialize.rb", "lib/prism/translation.rb", "lib/prism/translation/parser.rb", @@ -134,6 +135,7 @@ Gem::Specification.new do |spec| "sig/prism/pack.rbs", "sig/prism/parse_result.rbs", "sig/prism/pattern.rbs", + "sig/prism/reflection.rbs", "sig/prism/serialize.rbs", "sig/prism/visitor.rbs", "rbi/prism.rbi", @@ -143,6 +145,7 @@ Gem::Specification.new do |spec| "rbi/prism/node_ext.rbi", "rbi/prism/node.rbi", "rbi/prism/parse_result.rbi", + "rbi/prism/reflection.rbi", "rbi/prism/translation/parser/compiler.rbi", "rbi/prism/translation/ripper.rbi", "rbi/prism/translation/ripper/ripper_compiler.rbi", |