Skip to content

Commit

Permalink
Merge branch 'main' into rbconfig-make
Browse files Browse the repository at this point in the history
  • Loading branch information
ParadoxV5 committed Apr 14, 2024
2 parents 812d290 + 68074cf commit df5a134
Show file tree
Hide file tree
Showing 33 changed files with 641 additions and 198 deletions.
8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ updates:
directory: '/gemfiles/truffleruby'
schedule:
interval: 'weekly'
- package-ecosystem: 'bundler'
directory: '/gemfiles/typecheck'
schedule:
interval: 'weekly'
# - package-ecosystem: 'bundler'
# directory: '/gemfiles/typecheck'
# schedule:
# interval: 'weekly'
34 changes: 17 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ jobs:
env:
LANG: "C"

typecheck:
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: gemfiles/typecheck/Gemfile
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Check Sorbet
run: bundle exec rake typecheck:tapioca typecheck:sorbet
- name: Check Steep
run: bundle exec rake typecheck:steep
- name: Check field kinds
run: rm lib/prism/node.rb && CHECK_FIELD_KIND=true bundle exec rake
# typecheck:
# runs-on: ubuntu-latest
# env:
# BUNDLE_GEMFILE: gemfiles/typecheck/Gemfile
# steps:
# - uses: actions/checkout@v4
# - name: Set up Ruby
# uses: ruby/setup-ruby@v1
# with:
# ruby-version: "3.3"
# bundler-cache: true
# - name: Check Sorbet
# run: bundle exec rake typecheck:tapioca typecheck:sorbet
# - name: Check Steep
# run: bundle exec rake typecheck:steep
# - name: Check field kinds
# run: rm lib/prism/node.rb && CHECK_FIELD_KIND=true bundle exec rake

build:
strategy:
Expand Down
27 changes: 26 additions & 1 deletion bin/prism
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Prism
def run(argv)
case argv.shift
when "benchmark" then benchmark(argv)
when "bundle" then bundle(argv)
when "console" then console
when "dot" then dot(argv)
when "encoding" then encoding(argv)
Expand All @@ -23,6 +24,7 @@ module Prism
puts <<~TXT
Usage:
bin/prism benchmark [source_file]
bin/prism bundle [...]
bin/prism console
bin/prism dot [source]
bin/prism encoding [encoding]
Expand Down Expand Up @@ -86,6 +88,29 @@ module Prism
end
end

# bin/prism bundle [...]
def bundle(argv)
[
["2.7.8", ["2.7"]],
["3.0.6", ["3.0"]],
["3.1.4", ["3.1"]],
["3.2.3", ["3.2"]],
["3.3.0", ["3.3"]],
["3.4.0-dev", ["3.4", "typecheck"]],
["jruby-9.4.5.0", ["jruby"]],
["truffleruby-24.0.0", ["truffleruby"]]
].each do |ruby_version, gemfiles|
gemfiles.each do |gemfile|
system(
{ "BUNDLE_GEMFILE" => File.expand_path("../gemfiles/#{gemfile}/Gemfile", __dir__) },
"chruby-exec", ruby_version, "--", "bundle", *argv,
exception: true,
chdir: File.expand_path("../", __dir__)
)
end
end
end

# bin/prism console
def console
require "irb"
Expand Down Expand Up @@ -374,7 +399,7 @@ module Prism
case argv.first
when "-e"
argv.shift
Prism.parse(argv.shift)
Prism.parse(argv.shift, command_line: "e")
when nil
Prism.parse_file("test.rb")
else
Expand Down
5 changes: 4 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ errors:
- DEF_ENDLESS
- DEF_ENDLESS_SETTER
- DEF_NAME
- DEF_NAME_AFTER_RECEIVER
- DEF_PARAMS_TERM
- DEF_PARAMS_TERM_PAREN
- DEF_RECEIVER
Expand Down Expand Up @@ -97,6 +96,7 @@ errors:
- EXPECT_EXPRESSION_AFTER_STAR
- EXPECT_IDENT_REQ_PARAMETER
- EXPECT_LPAREN_REQ_PARAMETER
- EXPECT_MESSAGE
- EXPECT_RBRACKET
- EXPECT_RPAREN
- EXPECT_RPAREN_AFTER_MULTI
Expand Down Expand Up @@ -235,6 +235,7 @@ errors:
- TERNARY_EXPRESSION_TRUE
- UNARY_RECEIVER
- UNDEF_ARGUMENT
- UNEXPECTED_BLOCK_ARGUMENT
- UNEXPECTED_TOKEN_CLOSE_CONTEXT
- UNEXPECTED_TOKEN_IGNORE
- UNTIL_TERM
Expand Down Expand Up @@ -269,7 +270,9 @@ warnings:
- LITERAL_IN_CONDITION_VERBOSE
- SHEBANG_CARRIAGE_RETURN
- UNEXPECTED_CARRIAGE_RETURN
- UNREACHABLE_STATEMENT
- UNUSED_LOCAL_VARIABLE
- VOID_STATEMENT
tokens:
- name: EOF
value: 1
Expand Down
10 changes: 1 addition & 9 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,7 @@ bundle install
* Update the version-specific lockfiles:

```sh
chruby ruby-2.7.8 && BUNDLE_GEMFILE=gemfiles/2.7/Gemfile bundle install
chruby ruby-3.0.6 && BUNDLE_GEMFILE=gemfiles/3.0/Gemfile bundle install
chruby ruby-3.1.4 && BUNDLE_GEMFILE=gemfiles/3.1/Gemfile bundle install
chruby ruby-3.2.3 && BUNDLE_GEMFILE=gemfiles/3.2/Gemfile bundle install
chruby ruby-3.3.0 && BUNDLE_GEMFILE=gemfiles/3.3/Gemfile bundle install
chruby ruby-3.4.0-dev && BUNDLE_GEMFILE=gemfiles/3.4/Gemfile bundle install
chruby jruby-9.4.5.0 && BUNDLE_GEMFILE=gemfiles/jruby/Gemfile bundle install
chruby truffleruby-24.0.0 && BUNDLE_GEMFILE=gemfiles/truffleruby/Gemfile bundle install
chruby ruby-3.4.0-dev && BUNDLE_GEMFILE=gemfiles/typecheck/Gemfile bundle install
bin/prism bundle install
```

* Update the cargo lockfiles:
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/2.7/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GEM
racc
power_assert (2.0.3)
racc (1.7.3)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rbs (3.1.3)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/3.0/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GEM
racc
power_assert (2.0.3)
racc (1.7.3)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rbs (3.4.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/3.1/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GEM
racc
power_assert (2.0.3)
racc (1.7.3)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rbs (3.4.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/3.2/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GEM
racc
power_assert (2.0.3)
racc (1.7.3)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rbs (3.4.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/3.3/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GEM
racc
power_assert (2.0.3)
racc (1.7.3)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rbs (3.4.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/3.4/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GEM
racc
power_assert (2.0.3)
racc (1.7.3)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rbs (3.4.4)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/jruby/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GEM
racc
power_assert (2.0.3)
racc (1.7.3-java)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
test-unit (3.6.2)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/truffleruby/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GEM
racc
power_assert (2.0.3)
racc (1.7.3)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
test-unit (3.6.2)
Expand Down
4 changes: 2 additions & 2 deletions gemfiles/typecheck/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
prism (0.24.0)
prism (0.25.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -45,7 +45,7 @@ GEM
power_assert (2.0.3)
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rb-fsevent (0.11.2)
Expand Down
6 changes: 4 additions & 2 deletions lib/prism/desugar_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def initialize(node, source, read_class, write_class, *arguments)

# Desugar `x += y` to `x = x + y`
def compile
operator_loc = node.operator_loc.chop

write_class.new(
source,
*arguments,
Expand All @@ -82,8 +84,8 @@ def compile
0,
read_class.new(source, *arguments, node.name_loc),
nil,
node.operator_loc.slice.chomp("=").to_sym,
node.operator_loc.copy(length: node.operator_loc.length - 1),
operator_loc.slice.to_sym,
operator_loc,
nil,
ArgumentsNode.new(source, 0, [node.value], node.value.location),
nil,
Expand Down
5 changes: 5 additions & 0 deletions lib/prism/parse_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ def copy(source: self.source, start_offset: self.start_offset, length: self.leng
Location.new(source, start_offset, length)
end

# Returns a new location that is the result of chopping off the last byte.
def chop
copy(length: length == 0 ? length : length - 1)
end

# Returns a string representation of this location.
def inspect
"#<Prism::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
Expand Down
29 changes: 28 additions & 1 deletion lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,35 @@ def visit_interpolated_regular_expression_node(node)
def visit_interpolated_string_node(node)
if node.heredoc?
children, closing = visit_heredoc(node)
opening = token(node.opening_loc)

start_offset = node.opening_loc.end_offset + 1
end_offset = node.parts.first.location.start_offset

# In the below case, the offsets should be the same:
#
# <<~HEREDOC
# a #{b}
# HEREDOC
#
# But in this case, the end_offset would be greater than the start_offset:
#
# <<~HEREDOC
# #{b}
# HEREDOC
#
# So we need to make sure the result node's heredoc range is correct, without updating the children
result = if start_offset < end_offset
# We need to add a padding string to ensure that the heredoc has correct range for its body
padding_string_node = builder.string_internal(["", srange_offsets(start_offset, end_offset)])
node_with_correct_location = builder.string_compose(opening, [padding_string_node, *children], closing)
# But the padding string should not be included in the final AST, so we need to update the result's children
node_with_correct_location.updated(:dstr, children)
else
builder.string_compose(opening, children, closing)
end

return builder.string_compose(token(node.opening_loc), children, closing)
return result
end

parts = if node.parts.one? { |part| part.type == :string_node }
Expand Down
4 changes: 2 additions & 2 deletions rbi/prism.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Prism

sig { params(source: String, filepath: T.nilable(String), line: T.nilable(Integer), offset: T.nilable(Integer), encoding: T.nilable(Encoding), frozen_string_literal: T.nilable(T::Boolean), verbose: T.nilable(T::Boolean), scopes: T.nilable(T::Array[T::Array[Symbol]])).returns(Prism::ParseResult[Prism::ProgramNode]) }
def self.parse(source, filepath: nil, line: nil, offset: nil, encoding: nil, frozen_string_literal: nil, verbose: nil, scopes: nil); end

sig { params(filepath: String, line: T.nilable(Integer), offset: T.nilable(Integer), encoding: T.nilable(Encoding), frozen_string_literal: T.nilable(T::Boolean), verbose: T.nilable(T::Boolean), scopes: T.nilable(T::Array[T::Array[Symbol]])).returns(Prism::ParseResult[Prism::ProgramNode]) }
def self.parse_file(filepath, line: nil, offset: nil, encoding: nil, frozen_string_literal: nil, verbose: nil, scopes: nil); end

Expand All @@ -47,7 +47,7 @@ module Prism
def self.parse_success?(source, filepath: nil, line: nil, offset: nil, encoding: nil, frozen_string_literal: nil, verbose: nil, scopes: nil); end

sig { params(source: String, filepath: T.nilable(String), line: T.nilable(Integer), offset: T.nilable(Integer), encoding: T.nilable(Encoding), frozen_string_literal: T.nilable(T::Boolean), verbose: T.nilable(T::Boolean), scopes: T.nilable(T::Array[T::Array[Symbol]])).returns(T::Boolean) }
def self.parse_failure?(source, offset: nil, line: nil, offset: nil, encoding: nil, frozen_string_literal: nil, verbose: nil, scopes: nil); end
def self.parse_failure?(source, filepath: nil, line: nil, offset: nil, encoding: nil, frozen_string_literal: nil, verbose: nil, scopes: nil); end

sig { params(filepath: String, line: T.nilable(Integer), offset: T.nilable(Integer), encoding: T.nilable(Encoding), frozen_string_literal: T.nilable(T::Boolean), verbose: T.nilable(T::Boolean), scopes: T.nilable(T::Array[T::Array[Symbol]])).returns(T::Boolean) }
def self.parse_file_success?(filepath, line: nil, offset: nil, encoding: nil, frozen_string_literal: nil, verbose: nil, scopes: nil); end
Expand Down
3 changes: 3 additions & 0 deletions rbi/prism/parse_result.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class Prism::Location
sig { params(source: Prism::Source, start_offset: Integer, length: Integer).returns(Prism::Location) }
def copy(source: self.source, start_offset: self.start_offset, length: self.length); end

sig { returns(Prism::Location) }
def chop; end

sig { returns(String) }
def inspect; end

Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.lock

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

1 change: 1 addition & 0 deletions sig/prism/parse_result.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Prism
def trailing_comment: (comment) -> void
def comments: () -> Array[comment]
def copy: (?source: Source, ?start_offset: Integer, ?length: Integer) -> Location
def chop: () -> Location
def slice: () -> String
def start_character_offset: () -> Integer
def end_offset: () -> Integer
Expand Down
Loading

0 comments on commit df5a134

Please sign in to comment.