-
-
Notifications
You must be signed in to change notification settings - Fork 59
Combine LambdaVar
node with BlockVar
#303
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4982b6b
Combine the `LambdaVar` and `BlockVar` nodes
egiurleo 2779aac
Remmove `visit_lambda_var` method from visitors
egiurleo 19d8792
Remmove `visit_lambda_var` method from yarv compiler
egiurleo 4ec0070
Remove `LambdaVar` method from DSL and add new param to `BlockVar`
egiurleo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2131,13 +2131,18 @@ def ===(other) | |
end | ||
end | ||
|
||
# BlockVar represents the parameters being declared for a block. Effectively | ||
# this node is everything contained within the pipes. This includes all of the | ||
# various parameter types, as well as block-local variable declarations. | ||
# BlockVar represents the parameters being declared for a block or lambda. | ||
# This includes all of the various parameter types, as well as | ||
# block-local/lambda-local variable declarations. | ||
# | ||
# method do |positional, optional = value, keyword:, █ local| | ||
# end | ||
# | ||
# OR | ||
# | ||
# -> (positional, optional = value, keyword:, █ local) do | ||
# end | ||
# | ||
class BlockVar < Node | ||
# [Params] the parameters being declared with the block | ||
attr_reader :params | ||
|
@@ -2148,10 +2153,15 @@ class BlockVar < Node | |
# [Array[ Comment | EmbDoc ]] the comments attached to this node | ||
attr_reader :comments | ||
|
||
def initialize(params:, locals:, location:) | ||
# [boolean] whether or not the variables are within pipes | ||
attr_reader :pipe | ||
alias pipe? pipe | ||
|
||
def initialize(params:, locals:, location:, pipe:) | ||
@params = params | ||
@locals = locals | ||
@location = location | ||
@pipe = pipe | ||
@comments = [] | ||
end | ||
|
||
|
@@ -2163,12 +2173,13 @@ def child_nodes | |
[params, *locals] | ||
end | ||
|
||
def copy(params: nil, locals: nil, location: nil) | ||
def copy(params: nil, locals: nil, location: nil, pipe: nil) | ||
node = | ||
BlockVar.new( | ||
params: params || self.params, | ||
locals: locals || self.locals, | ||
location: location || self.location | ||
location: location || self.location, | ||
pipe: pipe || self.pipe | ||
) | ||
|
||
node.comments.concat(comments.map(&:copy)) | ||
|
@@ -2178,7 +2189,13 @@ def copy(params: nil, locals: nil, location: nil) | |
alias deconstruct child_nodes | ||
|
||
def deconstruct_keys(_keys) | ||
{ params: params, locals: locals, location: location, comments: comments } | ||
{ | ||
params: params, | ||
locals: locals, | ||
location: location, | ||
comments: comments, | ||
pipe: pipe | ||
} | ||
end | ||
|
||
# Within the pipes of the block declaration, we don't want any spaces. So | ||
|
@@ -2194,23 +2211,23 @@ def call(q) | |
SEPARATOR = Separator.new.freeze | ||
|
||
def format(q) | ||
q.text("|") | ||
q.group do | ||
q.remove_breaks(q.format(params)) | ||
pipe? ? q.remove_breaks(q.format(params)) : q.format(params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I managed to move the first two lines of this method into |
||
|
||
if locals.any? | ||
q.text("; ") | ||
q.seplist(locals, SEPARATOR) { |local| q.format(local) } | ||
end | ||
if locals.any? | ||
q.text("; ") | ||
q.seplist(locals, SEPARATOR) { |local| q.format(local) } | ||
end | ||
q.text("|") | ||
end | ||
|
||
def ===(other) | ||
other.is_a?(BlockVar) && params === other.params && | ||
ArrayMatch.call(locals, other.locals) | ||
end | ||
|
||
def empty? | ||
params.empty? && locals.empty? | ||
end | ||
|
||
# When a single required parameter is declared for a block, it gets | ||
# automatically expanded if the values being yielded into it are an array. | ||
def arg0? | ||
|
@@ -4486,8 +4503,9 @@ def format_break(q, break_opening, break_closing) | |
q.format(BlockOpenFormatter.new(break_opening, opening), stackable: false) | ||
|
||
if block_var | ||
q.text(" ") | ||
q.format(block_var) | ||
q.text(" |") | ||
q.group { q.format(block_var) } | ||
q.text("|") | ||
end | ||
|
||
unless bodystmt.empty? | ||
|
@@ -4507,7 +4525,9 @@ def format_flat(q, flat_opening, flat_closing) | |
|
||
if block_var | ||
q.breakable_space | ||
q.format(block_var) | ||
q.text("|") | ||
q.group { q.format(block_var) } | ||
q.text("|") | ||
q.breakable_space | ||
end | ||
|
||
|
@@ -7140,7 +7160,7 @@ def ===(other) | |
# ->(value) { value * 2 } | ||
# | ||
class Lambda < Node | ||
# [LambdaVar | Paren] the parameter declaration for this lambda | ||
# [BlockVar | Paren] the parameter declaration for this lambda | ||
attr_reader :params | ||
|
||
# [BodyStmt | Statements] the expressions to be executed in this lambda | ||
|
@@ -7258,76 +7278,6 @@ def ===(other) | |
end | ||
end | ||
|
||
# LambdaVar represents the parameters being declared for a lambda. Effectively | ||
# this node is everything contained within the parentheses. This includes all | ||
# of the various parameter types, as well as block-local variable | ||
# declarations. | ||
# | ||
# -> (positional, optional = value, keyword:, █ local) do | ||
# end | ||
# | ||
class LambdaVar < Node | ||
# [Params] the parameters being declared with the block | ||
attr_reader :params | ||
|
||
# [Array[ Ident ]] the list of block-local variable declarations | ||
attr_reader :locals | ||
|
||
# [Array[ Comment | EmbDoc ]] the comments attached to this node | ||
attr_reader :comments | ||
|
||
def initialize(params:, locals:, location:) | ||
@params = params | ||
@locals = locals | ||
@location = location | ||
@comments = [] | ||
end | ||
|
||
def accept(visitor) | ||
visitor.visit_lambda_var(self) | ||
end | ||
|
||
def child_nodes | ||
[params, *locals] | ||
end | ||
|
||
def copy(params: nil, locals: nil, location: nil) | ||
node = | ||
LambdaVar.new( | ||
params: params || self.params, | ||
locals: locals || self.locals, | ||
location: location || self.location | ||
) | ||
|
||
node.comments.concat(comments.map(&:copy)) | ||
node | ||
end | ||
|
||
alias deconstruct child_nodes | ||
|
||
def deconstruct_keys(_keys) | ||
{ params: params, locals: locals, location: location, comments: comments } | ||
end | ||
|
||
def empty? | ||
params.empty? && locals.empty? | ||
end | ||
|
||
def format(q) | ||
q.format(params) | ||
|
||
if locals.any? | ||
q.text("; ") | ||
q.seplist(locals, BlockVar::SEPARATOR) { |local| q.format(local) } | ||
end | ||
end | ||
|
||
def ===(other) | ||
other.is_a?(LambdaVar) && params === other.params && | ||
ArrayMatch.call(locals, other.locals) | ||
end | ||
end | ||
|
||
# LBrace represents the use of a left brace, i.e., {. | ||
class LBrace < Node | ||
# [String] the left brace | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.