Skip to content

Commit

Permalink
Update to latest prism
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Oct 26, 2023
1 parent ce4a9a8 commit 968fb74
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Main

on:
- push
- pull_request

jobs:
ci:
name: CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Test
run: bundle exec rake test
6 changes: 2 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../../ruby/prism
specs:
prism (0.14.0)
prism (0.15.1)

PATH
remote: .
Expand All @@ -14,7 +14,6 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
base64 (0.1.1)
benchmark-ips (2.12.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
Expand All @@ -28,8 +27,7 @@ GEM
rake (13.0.6)
regexp_parser (2.8.2)
rexml (3.2.6)
rubocop (1.57.1)
base64 (~> 0.1.1)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down
60 changes: 34 additions & 26 deletions lib/parser/prism/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,45 +252,27 @@ def visit_call_node(node)

# foo.bar += baz
# ^^^^^^^^^^^^^^^
#
# foo[bar] += baz
# ^^^^^^^^^^^^^^^
def visit_call_operator_write_node(node)
builder.op_assign(
if node.read_name == :[]
builder.index(
visit(node.receiver),
token(node.opening_loc),
visit(node.arguments) || [],
token(node.closing_loc)
)
else
builder.call_method(
visit(node.receiver),
node.call_operator_loc ? [{ "." => :dot, "&." => :anddot, "::" => "::" }.fetch(node.call_operator), srange(node.call_operator_loc)] : nil,
node.message_loc ? [node.read_name, srange(node.message_loc)] : nil,
token(node.opening_loc),
visit(node.arguments) || [],
token(node.closing_loc)
)
end,
builder.call_method(
visit(node.receiver),
node.call_operator_loc ? [{ "." => :dot, "&." => :anddot, "::" => "::" }.fetch(node.call_operator), srange(node.call_operator_loc)] : nil,
node.message_loc ? [node.read_name, srange(node.message_loc)] : nil,
nil,
[],
nil
),
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
visit(node.value)
)
end

# foo.bar &&= baz
# ^^^^^^^^^^^^^^^
#
# foo[bar] &&= baz
# ^^^^^^^^^^^^^^^^
alias visit_call_and_write_node visit_call_operator_write_node

# foo.bar ||= baz
# ^^^^^^^^^^^^^^^
#
# foo[bar] ||= baz
# ^^^^^^^^^^^^^^^^
alias visit_call_or_write_node visit_call_operator_write_node

# foo => bar => baz
Expand Down Expand Up @@ -766,6 +748,32 @@ def visit_in_node(node)
)
end

# foo[bar] += baz
# ^^^^^^^^^^^^^^^
def visit_index_operator_write_node(node)
arguments = node.arguments&.arguments || []
arguments << node.block if node.block

builder.op_assign(
builder.index(
visit(node.receiver),
token(node.opening_loc),
visit_all(arguments),
token(node.closing_loc)
),
[node.operator_loc.slice.chomp("="), srange(node.operator_loc)],
visit(node.value)
)
end

# foo[bar] &&= baz
# ^^^^^^^^^^^^^^^^
alias visit_index_and_write_node visit_index_operator_write_node

# foo[bar] ||= baz
# ^^^^^^^^^^^^^^^^
alias visit_index_or_write_node visit_index_operator_write_node

# @foo
# ^^^^
def visit_instance_variable_read_node(node)
Expand Down

0 comments on commit 968fb74

Please sign in to comment.