Skip to content
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
6 changes: 4 additions & 2 deletions ext/prism/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,11 @@ file_options(int argc, VALUE *argv, pm_options_t *options, VALUE *encoded_filepa
VALUE keywords;
rb_scan_args(argc, argv, "1:", &filepath, &keywords);

if (!RB_TYPE_P(filepath, T_STRING)) {
int state = 0;
filepath = rb_protect(rb_get_path, filepath, &state);
if (state != 0) {
pm_options_free(options);
rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected String)", rb_obj_class(filepath));
rb_jump_tag(state);
}

*encoded_filepath = rb_str_encode_ospath(filepath);
Expand Down
16 changes: 8 additions & 8 deletions lib/prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ def self.find(callable)
# def self.parse_success?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
# def self.parse_failure?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
# def self.parse_stream: (_Stream stream, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
# def self.parse_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
# def self.profile_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void
# def self.lex_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult
# def self.parse_lex_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult
# def self.dump_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String
# def self.parse_file_comments: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment]
# def self.parse_file_success?: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
# def self.parse_file_failure?: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
# def self.parse_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
# def self.profile_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void
# def self.lex_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult
# def self.parse_lex_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult
# def self.dump_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String
# def self.parse_file_comments: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment]
# def self.parse_file_success?: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
# def self.parse_file_failure?: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
end

require_relative "prism/polyfill/byteindex"
Expand Down
29 changes: 13 additions & 16 deletions lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ def self.with_string(string)
end

# Yields a PrismSource to the given block, backed by a pm_source_t.
def self.with_file(filepath)
def self.with_file(filepath, options)
unless filepath.is_a?(String)
filepath = filepath.to_path if filepath.respond_to?(:to_path)
filepath = filepath.to_str if filepath.respond_to?(:to_str)
end
options[:filepath] = filepath
raise TypeError unless filepath.is_a?(String)

# On Windows and Mac, it's expected that filepaths will be encoded in
Expand Down Expand Up @@ -265,8 +270,7 @@ def dump(source, **options)

# Mirror the Prism.dump_file API by using the serialization API.
def dump_file(filepath, **options)
options[:filepath] = filepath
LibRubyParser::PrismSource.with_file(filepath) { |string| dump_common(string, options) }
LibRubyParser::PrismSource.with_file(filepath, options) { |string| dump_common(string, options) }
end

# Mirror the Prism.lex API by using the serialization API.
Expand All @@ -276,8 +280,7 @@ def lex(code, **options)

# Mirror the Prism.lex_file API by using the serialization API.
def lex_file(filepath, **options)
options[:filepath] = filepath
LibRubyParser::PrismSource.with_file(filepath) { |string| lex_common(string, string.read, options) }
LibRubyParser::PrismSource.with_file(filepath, options) { |string| lex_common(string, string.read, options) }
end

# Mirror the Prism.parse API by using the serialization API.
Expand All @@ -289,8 +292,7 @@ def parse(code, **options)
# native strings instead of Ruby strings because it allows us to use mmap
# when it is available.
def parse_file(filepath, **options)
options[:filepath] = filepath
LibRubyParser::PrismSource.with_file(filepath) { |string| parse_common(string, string.read, options) }
LibRubyParser::PrismSource.with_file(filepath, options) { |string| parse_common(string, string.read, options) }
end

# Mirror the Prism.parse_stream API by using the serialization API.
Expand Down Expand Up @@ -349,8 +351,7 @@ def parse_comments(code, **options)
# API. This uses native strings instead of Ruby strings because it allows us
# to use mmap when it is available.
def parse_file_comments(filepath, **options)
options[:filepath] = filepath
LibRubyParser::PrismSource.with_file(filepath) { |string| parse_comments_common(string, string.read, options) }
LibRubyParser::PrismSource.with_file(filepath, options) { |string| parse_comments_common(string, string.read, options) }
end

# Mirror the Prism.parse_lex API by using the serialization API.
Expand All @@ -360,8 +361,7 @@ def parse_lex(code, **options)

# Mirror the Prism.parse_lex_file API by using the serialization API.
def parse_lex_file(filepath, **options)
options[:filepath] = filepath
LibRubyParser::PrismSource.with_file(filepath) { |string| parse_lex_common(string, string.read, options) }
LibRubyParser::PrismSource.with_file(filepath, options) { |string| parse_lex_common(string, string.read, options) }
end

# Mirror the Prism.parse_success? API by using the serialization API.
Expand All @@ -376,8 +376,7 @@ def parse_failure?(code, **options)

# Mirror the Prism.parse_file_success? API by using the serialization API.
def parse_file_success?(filepath, **options)
options[:filepath] = filepath
LibRubyParser::PrismSource.with_file(filepath) { |string| parse_file_success_common(string, options) }
LibRubyParser::PrismSource.with_file(filepath, options) { |string| parse_file_success_common(string, options) }
end

# Mirror the Prism.parse_file_failure? API by using the serialization API.
Expand All @@ -401,9 +400,7 @@ def profile(source, **options)

# Mirror the Prism.profile_file API by using the serialization API.
def profile_file(filepath, **options)
LibRubyParser::PrismSource.with_file(filepath) do |string|
options[:filepath] = filepath

LibRubyParser::PrismSource.with_file(filepath, options) do |string|
if (format_type = raise_error_format_type(options))
raise_error(string, options, format_type)
end
Expand Down
2 changes: 2 additions & 0 deletions rakelib/typecheck.rake
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ namespace :typecheck do
RBI::Type.generic("T::Hash", RBI::Type.simple("Symbol"), RBI::Type.untyped)
when :entry_value
RBI::Type.untyped
when :path
RBI::Type.any(RBI::Type.simple("String"), RBI::Type.simple("Pathname"), RBI::Type.simple("IO"))
when :boolish
RBI::Type.nilable(RBI::Type.boolean)
else
Expand Down
16 changes: 8 additions & 8 deletions rbi/generated/prism.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading