Skip to content

Commit 0402191

Browse files
committed
Rename to prism
1 parent 8b06c76 commit 0402191

File tree

8 files changed

+52
-36
lines changed

8 files changed

+52
-36
lines changed

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
source "https://rubygems.org"
44

55
gemspec
6+
7+
if File.directory?("../../ruby/prism")
8+
gem "prism", path: "../../ruby/prism"
9+
end

Gemfile.lock

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1+
PATH
2+
remote: ../../ruby/prism
3+
specs:
4+
prism (0.12.0)
5+
16
PATH
27
remote: .
38
specs:
4-
syntax_tree-yarp (0.1.0)
9+
syntax_tree-prism (0.1.0)
510
prettier_print (>= 1.2.0)
6-
yarp (>= 0.12.0)
11+
prism (>= 0.12.0)
712

813
GEM
914
remote: https://rubygems.org/
1015
specs:
1116
prettier_print (1.2.1)
12-
yarp (0.12.0)
1317

1418
PLATFORMS
1519
arm64-darwin-22
1620

1721
DEPENDENCIES
18-
syntax_tree-yarp!
22+
prism!
23+
syntax_tree-prism!
1924

2025
BUNDLED WITH
2126
2.4.13

bin/format

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
require "bundler/setup"
44

55
$:.unshift(File.expand_path("../lib", __dir__))
6-
require "syntax_tree/yarp"
6+
require "syntax_tree/prism"
77

88
result =
99
if ARGV[0] == "-e"
10-
YARP.parse(ARGV[1])
10+
Prism.parse(ARGV[1])
1111
else
12-
YARP.parse_file(ARGV[0])
12+
Prism.parse_file(ARGV[0])
1313
end
1414

1515
puts result.format

bin/test

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "bundler/setup"
55

66
$:.unshift(File.expand_path("../lib", __dir__))
7-
require "syntax_tree/yarp"
7+
require "syntax_tree/prism"
88

99
END {
1010
failures = DATA.readlines(chomp: true)
@@ -18,7 +18,7 @@ END {
1818
source, formatted = source.tap(&:shift).join.split("-\n")
1919
formatted ||= source
2020

21-
actual = YARP.parse(source).format
21+
actual = Prism.parse(source).format
2222
name = "#{File.basename(filepath)}:#{index}"
2323

2424
if actual != formatted
@@ -33,10 +33,10 @@ END {
3333

3434
puts failures
3535

36-
YARP::TESTS.each do |clazz, cases|
36+
Prism::TESTS.each do |clazz, cases|
3737
cases.each do |(output, input, block)|
3838
output = output.gsub("{{long}}", "a" * 80)
39-
result = YARP.parse(input.gsub("{{long}}", "a" * 80))
39+
result = Prism.parse(input.gsub("{{long}}", "a" * 80))
4040

4141
node = result.value.statements.body.last
4242
node = block.call(node) if block

lib/syntax_tree/yarp.rb renamed to lib/syntax_tree/prism.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
require "prettier_print"
4-
require "yarp"
4+
require "prism"
55

6-
module YARP
6+
module Prism
77
class ParseResult
88
# Format the syntax tree using the default options.
99
def format
@@ -25,5 +25,5 @@ def self.test(output, input = output, &block)
2525
end
2626
end
2727

28-
require "syntax_tree/yarp/formatter"
29-
require "syntax_tree/yarp/nodes"
28+
require "syntax_tree/prism/formatter"
29+
require "syntax_tree/prism/nodes"

lib/syntax_tree/yarp/formatter.rb renamed to lib/syntax_tree/prism/formatter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module YARP
3+
module Prism
44
# A slightly enhanced PrettierPrint that knows how to format recursively
55
# including comments.
66
class Formatter < PrettierPrint

lib/syntax_tree/yarp/nodes.rb renamed to lib/syntax_tree/prism/nodes.rb

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
module YARP
3+
module Prism
44
class Comment
55
def slice
66
location.slice
@@ -508,7 +508,14 @@ class CallNode
508508
def format(q)
509509
message = self.message
510510
name = self.name
511-
arguments = self.arguments
511+
512+
arguments = [*self.arguments&.arguments]
513+
block = self.block
514+
515+
if block.is_a?(BlockArgumentNode)
516+
arguments << block
517+
block = nil
518+
end
512519

513520
unless safe_navigation?
514521
case name.to_sym
@@ -532,28 +539,28 @@ def format(q)
532539
return
533540
end
534541

535-
if !arguments && !block
542+
if arguments.empty? && block.nil?
536543
q.format_prefix(message_loc, receiver)
537544
return
538545
end
539546
when :+@, :-@, :~
540-
if !arguments && !block
547+
if arguments.empty? && block.nil?
541548
q.format_prefix(message_loc, receiver)
542549
return
543550
end
544551
when :+, :-, :*, :/, :==, :>, :<, :>=, :<=, :<=>, :<<, :>>
545-
if arguments&.arguments.length == 1 && !block
546-
q.format_binary(receiver, message_loc, arguments)
552+
if arguments.length == 1 && block.nil?
553+
q.format_binary(receiver, message_loc, arguments.first)
547554
return
548555
end
549556
when :**
550-
if arguments&.arguments.length == 1 && !block
557+
if arguments.length == 1 && block.nil?
551558
q.group do
552559
q.format(receiver)
553560
q.text("**")
554561
q.indent do
555562
q.breakable_empty
556-
q.format(arguments)
563+
q.seplist(arguments) { |argument| q.format(argument) }
557564
end
558565
end
559566

@@ -564,10 +571,10 @@ def format(q)
564571
q.format(receiver)
565572
q.text("[")
566573

567-
if arguments
574+
if arguments.any?
568575
q.indent do
569576
q.breakable_empty
570-
q.format(arguments)
577+
q.seplist(arguments) { |argument| q.format(argument) }
571578
end
572579

573580
q.breakable_empty
@@ -583,9 +590,9 @@ def format(q)
583590

584591
return
585592
when :[]=
586-
if arguments
593+
if arguments.any?
587594
q.group do
588-
*before, after = arguments.arguments
595+
*before, after = arguments
589596

590597
q.group do
591598
q.format(receiver)
@@ -644,21 +651,21 @@ def format(q)
644651
q.text(message)
645652
end
646653

647-
if arguments && arguments.arguments.length == 1 && name.end_with?("=") && !block
654+
if arguments.length == 1 && name.end_with?("=") && block.nil?
648655
q.text(" =")
649656
q.indent do
650657
q.breakable_space
651-
q.format(arguments)
658+
q.seplist(arguments) { |argument| q.format(argument) }
652659
end
653-
elsif opening_loc && arguments && closing_loc
660+
elsif opening_loc && arguments.any? && closing_loc
654661
q.text("(")
655662
q.indent do
656663
q.breakable_empty
657-
q.format(arguments)
664+
q.seplist(arguments) { |argument| q.format(argument) }
658665
end
659666
q.breakable_empty
660667
q.text(")")
661-
elsif arguments
668+
elsif arguments.any?
662669
q.text(" ")
663670
align(q, self, q.last_position(doc))
664671
elsif opening_loc && closing_loc

syntax_tree-yarp.gemspec renamed to syntax_tree-prism.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# frozen_string_literal: true
22

33
Gem::Specification.new do |spec|
4-
spec.name = "syntax_tree-yarp"
4+
spec.name = "syntax_tree-prism"
55
spec.version = "0.1.0"
66
spec.authors = ["Kevin Newton"]
77
spec.email = ["[email protected]"]
88

99
spec.summary = "WIP"
10-
spec.homepage = "https://github.com/ruby-syntax-tree/syntax_tree-yarp"
10+
spec.homepage = "https://github.com/ruby-syntax-tree/syntax_tree-prism"
1111
spec.license = "MIT"
1212
spec.metadata = { "rubygems_mfa_required" => "true" }
1313

@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
2222
spec.require_paths = %w[lib]
2323

2424
spec.add_dependency "prettier_print", ">= 1.2.0"
25-
spec.add_dependency "yarp", ">= 0.12.0"
25+
spec.add_dependency "prism", ">= 0.12.0"
2626
end

0 commit comments

Comments
 (0)