Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitafa9f88

Browse files
committed
AliasNode: {left, right} -> {new_name, old_name}
-Fixes#348 except for the `keyword_loc`
1 parentd08d23b commitafa9f88

File tree

8 files changed

+55
-37
lines changed

8 files changed

+55
-37
lines changed

‎lib/syntax_tree/dsl.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ def EndContent(value)
3232
end
3333

3434
# Create a new AliasNode node.
35-
defAliasNode(left,right)
36-
AliasNode.new(left:left,right:right,location:Location.default)
35+
defAliasNode(new_name,old_name)
36+
AliasNode.new(
37+
new_name:new_name,
38+
old_name:old_name,
39+
location:Location.default
40+
)
3741
end
3842

3943
# Create a new ARef node.

‎lib/syntax_tree/field_visitor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def visit_aref_field(node)
6767

6868
defvisit_alias(node)
6969
node(node,"alias")do
70-
field("left",node.left)
71-
field("right",node.right)
70+
field("new_name",node.new_name)
71+
field("old_name",node.old_name)
7272
comments(node)
7373
end
7474
end

‎lib/syntax_tree/index.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ def initialize
475475

476476
visit_methodsdo
477477
defvisit_alias(node)
478-
ifnode.left.is_a?(SymbolLiteral) &&node.right.is_a?(SymbolLiteral)
478+
ifnode.new_name.is_a?(SymbolLiteral) &&
479+
node.old_name.is_a?(SymbolLiteral)
479480
location=
480481
Location.new(
481482
node.location.start_line,
@@ -484,7 +485,7 @@ def visit_alias(node)
484485

485486
results <<AliasMethodDefinition.new(
486487
nesting.dup,
487-
node.left.value.value.to_sym,
488+
node.new_name.value.value.to_sym,
488489
location,
489490
comments_for(node)
490491
)

‎lib/syntax_tree/mutation_visitor.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ def visit___end__(node)
6262

6363
# Visit a AliasNode node.
6464
defvisit_alias(node)
65-
node.copy(left:visit(node.left),right:visit(node.right))
65+
node.copy(
66+
new_name:visit(node.new_name),
67+
old_name:visit(node.old_name)
68+
)
6669
end
6770

6871
# Visit a ARef node.

‎lib/syntax_tree/node.rb

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,17 @@ def format(q)
485485
end
486486

487487
# [DynaSymbol | GVar | SymbolLiteral] the new name of the method
488-
attr_reader:left
488+
attr_reader:new_name
489489

490490
# [Backref | DynaSymbol | GVar | SymbolLiteral] the old name of the method
491-
attr_reader:right
491+
attr_reader:old_name
492492

493493
# [Array[ Comment | EmbDoc ]] the comments attached to this node
494494
attr_reader:comments
495495

496-
definitialize(left:,right:,location:)
497-
@left=left
498-
@right=right
496+
definitialize(new_name:,old_name:,location:)
497+
@new_name=new_name
498+
@old_name=old_name
499499
@location=location
500500
@comments=[]
501501
end
@@ -505,14 +505,14 @@ def accept(visitor)
505505
end
506506

507507
defchild_nodes
508-
[left,right]
508+
[new_name,old_name]
509509
end
510510

511-
defcopy(left:nil,right:nil,location:nil)
511+
defcopy(new_name:nil,old_name:nil,location:nil)
512512
node=
513513
AliasNode.new(
514-
left:left ||self.left,
515-
right:right ||self.right,
514+
new_name:new_name ||self.new_name,
515+
old_name:old_name ||self.old_name,
516516
location:location ||self.location
517517
)
518518

@@ -523,31 +523,41 @@ def copy(left: nil, right: nil, location: nil)
523523
aliasdeconstructchild_nodes
524524

525525
defdeconstruct_keys(_keys)
526-
{left:left,right:right,location:location,comments:comments}
526+
{
527+
new_name:new_name,
528+
old_name:old_name,
529+
location:location,
530+
comments:comments
531+
}
527532
end
528533

529534
defformat(q)
530535
keyword="alias "
531-
left_argument=AliasArgumentFormatter.new(left)
536+
new_name_argument=AliasArgumentFormatter.new(new_name)
532537

533538
q.groupdo
534539
q.text(keyword)
535-
q.format(left_argument,stackable:false)
540+
q.format(new_name_argument,stackable:false)
536541
q.groupdo
537542
q.nest(keyword.length)do
538-
left_argument.comments.any? ?q.breakable_force :q.breakable_space
539-
q.format(AliasArgumentFormatter.new(right),stackable:false)
543+
ifnew_name_argument.comments.any?
544+
q.breakable_force
545+
else
546+
q.breakable_space
547+
end
548+
q.format(AliasArgumentFormatter.new(old_name),stackable:false)
540549
end
541550
end
542551
end
543552
end
544553

545554
def ===(other)
546-
other.is_a?(AliasNode) &&left ===other.left &&right ===other.right
555+
other.is_a?(AliasNode) &&new_name ===other.new_name &&
556+
old_name ===other.old_name
547557
end
548558

549559
defvar_alias?
550-
left.is_a?(GVar)
560+
new_name.is_a?(GVar)
551561
end
552562
end
553563

‎lib/syntax_tree/parser.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,16 @@ def on___end__(value)
447447

448448
# :call-seq:
449449
# on_alias: (
450-
# (DynaSymbol | SymbolLiteral)left,
451-
# (DynaSymbol | SymbolLiteral)right
450+
# (DynaSymbol | SymbolLiteral)new_name,
451+
# (DynaSymbol | SymbolLiteral)old_name
452452
# ) -> AliasNode
453-
defon_alias(left,right)
453+
defon_alias(new_name,old_name)
454454
keyword=consume_keyword(:alias)
455455

456456
AliasNode.new(
457-
left:left,
458-
right:right,
459-
location:keyword.location.to(right.location)
457+
new_name:new_name,
458+
old_name:old_name,
459+
location:keyword.location.to(old_name.location)
460460
)
461461
end
462462

@@ -3902,14 +3902,14 @@ def on_until_mod(predicate, statement)
39023902
end
39033903

39043904
# :call-seq:
3905-
# on_var_alias: (GVarleft, (Backref | GVar)right) -> AliasNode
3906-
defon_var_alias(left,right)
3905+
# on_var_alias: (GVarnew_name, (Backref | GVar)old_name) -> AliasNode
3906+
defon_var_alias(new_name,old_name)
39073907
keyword=consume_keyword(:alias)
39083908

39093909
AliasNode.new(
3910-
left:left,
3911-
right:right,
3912-
location:keyword.location.to(right.location)
3910+
new_name:new_name,
3911+
old_name:old_name,
3912+
location:keyword.location.to(old_name.location)
39133913
)
39143914
end
39153915

‎lib/syntax_tree/translation/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def visit(node)
9494
defvisit_alias(node)
9595
s(
9696
:alias,
97-
[visit(node.left),visit(node.right)],
97+
[visit(node.new_name),visit(node.old_name)],
9898
smap_keyword_bare(
9999
srange_length(node.start_char,5),
100100
srange_node(node)

‎lib/syntax_tree/yarv/compiler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ def visit_END(node)
339339
defvisit_alias(node)
340340
iseq.putspecialobject(PutSpecialObject::OBJECT_VMCORE)
341341
iseq.putspecialobject(PutSpecialObject::OBJECT_CBASE)
342-
visit(node.left)
343-
visit(node.right)
342+
visit(node.new_name)
343+
visit(node.old_name)
344344
iseq.send(YARV.calldata(:"core#set_method_alias",3))
345345
end
346346

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp