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

AliasNode: {left, right} -> {new_name, old_name}#370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
davidwessman wants to merge1 commit intoruby-syntax-tree:structure
base:structure
Choose a base branch
Loading
fromdavidwessman:348-alias-node-restructuring
Open
Show file tree
Hide file tree
Changes fromall 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
8 changes: 6 additions & 2 deletionslib/syntax_tree/dsl.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,8 +32,12 @@ def EndContent(value)
end

# Create a new AliasNode node.
def AliasNode(left, right)
AliasNode.new(left: left, right: right, location: Location.default)
def AliasNode(new_name, old_name)
AliasNode.new(
new_name: new_name,
old_name: old_name,
location: Location.default
)
end

# Create a new AndNode node.
Expand Down
4 changes: 2 additions & 2 deletionslib/syntax_tree/field_visitor.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,8 +67,8 @@ def visit_aref_field(node)

def visit_alias(node)
node(node, "alias") do
field("left", node.left)
field("right", node.right)
field("new_name", node.new_name)
field("old_name", node.old_name)
comments(node)
end
end
Expand Down
5 changes: 3 additions & 2 deletionslib/syntax_tree/index.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -475,7 +475,8 @@ def initialize

visit_methods do
def visit_alias(node)
if node.left.is_a?(SymbolLiteral) && node.right.is_a?(SymbolLiteral)
if node.new_name.is_a?(SymbolLiteral) &&
node.old_name.is_a?(SymbolLiteral)
location =
Location.new(
node.location.start_line,
Expand All@@ -484,7 +485,7 @@ def visit_alias(node)

results << AliasMethodDefinition.new(
nesting.dup,
node.left.value.value.to_sym,
node.new_name.value.value.to_sym,
location,
comments_for(node)
)
Expand Down
5 changes: 4 additions & 1 deletionlib/syntax_tree/mutation_visitor.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,10 @@ def visit___end__(node)

# Visit a AliasNode node.
def visit_alias(node)
node.copy(left: visit(node.left), right: visit(node.right))
node.copy(
new_name: visit(node.new_name),
old_name: visit(node.old_name)
)
end

# Visit a AndNode node.
Expand Down
42 changes: 26 additions & 16 deletionslib/syntax_tree/node.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -485,17 +485,17 @@ def format(q)
end

# [DynaSymbol | GVar | SymbolLiteral] the new name of the method
attr_reader :left
attr_reader :new_name

# [Backref | DynaSymbol | GVar | SymbolLiteral] the old name of the method
attr_reader :right
attr_reader :old_name

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

def initialize(left:,right:, location:)
@left =left
@right =right
def initialize(new_name:,old_name:, location:)
@new_name =new_name
@old_name =old_name
@location = location
@comments = []
end
Expand All@@ -505,14 +505,14 @@ def accept(visitor)
end

def child_nodes
[left, right]
[new_name, old_name]
end

def copy(left: nil,right: nil, location: nil)
def copy(new_name: nil,old_name: nil, location: nil)
node =
AliasNode.new(
left: left || self.left,
right: right || self.right,
new_name: new_name || self.new_name,
old_name: old_name || self.old_name,
location: location || self.location
)

Expand All@@ -523,31 +523,41 @@ def copy(left: nil, right: nil, location: nil)
alias deconstruct child_nodes

def deconstruct_keys(_keys)
{ left: left, right: right, location: location, comments: comments }
{
new_name: new_name,
old_name: old_name,
location: location,
comments: comments
}
end

def format(q)
keyword = "alias "
left_argument = AliasArgumentFormatter.new(left)
new_name_argument = AliasArgumentFormatter.new(new_name)

q.group do
q.text(keyword)
q.format(left_argument, stackable: false)
q.format(new_name_argument, stackable: false)
q.group do
q.nest(keyword.length) do
left_argument.comments.any? ? q.breakable_force : q.breakable_space
q.format(AliasArgumentFormatter.new(right), stackable: false)
if new_name_argument.comments.any?
q.breakable_force
else
q.breakable_space
end
q.format(AliasArgumentFormatter.new(old_name), stackable: false)
end
end
end
end

def ===(other)
other.is_a?(AliasNode) && left === other.left && right === other.right
other.is_a?(AliasNode) && new_name === other.new_name &&
old_name === other.old_name
end

def var_alias?
left.is_a?(GVar)
new_name.is_a?(GVar)
end
end

Expand Down
22 changes: 11 additions & 11 deletionslib/syntax_tree/parser.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -447,16 +447,16 @@ def on___end__(value)

# :call-seq:
# on_alias: (
# (DynaSymbol | SymbolLiteral)left,
# (DynaSymbol | SymbolLiteral)right
# (DynaSymbol | SymbolLiteral)new_name,
# (DynaSymbol | SymbolLiteral)old_name
# ) -> AliasNode
def on_alias(left, right)
def on_alias(new_name, old_name)
keyword = consume_keyword(:alias)

AliasNode.new(
left: left,
right: right,
location: keyword.location.to(right.location)
new_name: new_name,
old_name: old_name,
location: keyword.location.to(old_name.location)
)
end

Expand DownExpand Up@@ -3912,14 +3912,14 @@ def on_until_mod(predicate, statement)
end

# :call-seq:
# on_var_alias: (GVarleft, (Backref | GVar)right) -> AliasNode
def on_var_alias(left, right)
# on_var_alias: (GVarnew_name, (Backref | GVar)old_name) -> AliasNode
def on_var_alias(new_name, old_name)
keyword = consume_keyword(:alias)

AliasNode.new(
left: left,
right: right,
location: keyword.location.to(right.location)
new_name: new_name,
old_name: old_name,
location: keyword.location.to(old_name.location)
)
end

Expand Down
2 changes: 1 addition & 1 deletionlib/syntax_tree/translation/parser.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -94,7 +94,7 @@ def visit(node)
def visit_alias(node)
s(
:alias,
[visit(node.left), visit(node.right)],
[visit(node.new_name), visit(node.old_name)],
smap_keyword_bare(
srange_length(node.start_char, 5),
srange_node(node)
Expand Down
4 changes: 2 additions & 2 deletionslib/syntax_tree/yarv/compiler.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -339,8 +339,8 @@ def visit_END(node)
def visit_alias(node)
iseq.putspecialobject(PutSpecialObject::OBJECT_VMCORE)
iseq.putspecialobject(PutSpecialObject::OBJECT_CBASE)
visit(node.left)
visit(node.right)
visit(node.new_name)
visit(node.old_name)
iseq.send(YARV.calldata(:"core#set_method_alias", 3))
end

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp