-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PrismScanner: Rewrite to avoid implementing visit
- This rewrites the Visitor to avoid implementing visit for every available node type and instead let the Prism::Visitor visit ALL nodes.
- Loading branch information
1 parent
1b47f72
commit 0bcccee
Showing
7 changed files
with
470 additions
and
799 deletions.
There are no files selected for viewing
This file contains 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
41 changes: 41 additions & 0 deletions
41
lib/i18n/tasks/scanners/prism_scanners/arguments_visitor.rb
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'prism/visitor' | ||
|
||
# This class is used to parse the arguments to e.g. a Prism::CallNode and return the values we need | ||
# for turning them into translations and occurrences. | ||
# Used in the PrismScanners::Visitor class. | ||
module I18n::Tasks::Scanners::PrismScanners | ||
class ArgumentsVisitor < Prism::Visitor | ||
def visit_keyword_hash_node(node) | ||
node.child_nodes.each_with_object({}) do |child, hash| | ||
hash[visit(child.key)] = visit(child.value) | ||
hash | ||
end | ||
end | ||
|
||
def visit_symbol_node(node) | ||
node.value | ||
end | ||
|
||
def visit_string_node(node) | ||
node.content | ||
end | ||
|
||
def visit_array_node(node) | ||
node.child_nodes.map { |child| visit(child) } | ||
end | ||
|
||
def visit_arguments_node(node) | ||
node.child_nodes.map { |child| visit(child) } | ||
end | ||
|
||
def visit_integer_node(node) | ||
node.value | ||
end | ||
|
||
def visit_lambda_node(node) | ||
node | ||
end | ||
end | ||
end |
Oops, something went wrong.