summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGopal Patel <[email protected]>2024-01-08 10:31:37 -0800
committergit <[email protected]>2024-02-24 03:39:22 +0000
commit7556fd937cfedbee9775b92124fcdce5c416dd50 ()
tree55bca2cd9e0dce4543c8e086bda52d3c2158e1a6 /lib
parente03e9c3644c3c5a8713e1fed547da0c0becf36de (diff)
[ruby/prism] Split private types
https://.com/ruby/prism/commit/0209d093ec
-rw-r--r--lib/prism/node_ext.rb7
-rw-r--r--lib/prism/pack.rb1
-rw-r--r--lib/prism/parse_result.rb12
-rw-r--r--lib/prism/parse_result/comments.rb1
-rw-r--r--lib/prism/parse_result/newlines.rb6
-rw-r--r--lib/prism/pattern.rb22
-rw-r--r--lib/prism/prism.gemspec9
7 files changed, 36 insertions, 22 deletions
@@ -169,14 +169,17 @@ module Prism
class ParametersNode < Node
# Mirrors the Method#parameters method.
def signature
- names = [] #: Array[[:req | :opt | :rest | :keyreq | :key | :keyrest | :block, Symbol] | [:rest | :keyrest | :nokey]]
requireds.each do |param|
names << (param.is_a?(MultiTargetNode) ? [:req] : [:req, param.name])
end
optionals.each { |param| names << [:opt, param.name] }
- names << [:rest, rest.name || :*] if rest
posts.each do |param|
names << (param.is_a?(MultiTargetNode) ? [:req] : [:req, param.name])
@@ -216,6 +216,7 @@ module Prism
else
source = directive.source
end
" #{source.ljust(source_width)} #{directive.describe}"
end
@@ -30,7 +30,7 @@ module Prism
# Perform a byteslice on the source code using the given byte offset and
# byte length.
def slice(byte_offset, length)
- source.byteslice(byte_offset, length)
end
# Binary search through the offsets to find the line number for the given
@@ -52,7 +52,7 @@ module Prism
# Return the character offset for the given byte offset.
def character_offset(byte_offset)
- source.byteslice(0, byte_offset).length
end
# Return the column number in characters for the given byte offset.
@@ -157,12 +157,8 @@ module Prism
end
# Create a new location object with the given options.
- def copy(**options)
- Location.new(
- options.fetch(:source) { source },
- options.fetch(:start_offset) { start_offset },
- options.fetch(:length) { length }
- )
end
# Returns a string representation of this location.
@@ -150,6 +150,7 @@ module Prism
target_end = target.end_offset
if target.encloses?(comment)
# The comment is completely contained by this target. Abandon the
# binary search at this level.
return nearest_targets(target.node, comment)
@@ -58,7 +58,11 @@ module Prism
# Walk the tree and mark nodes that are on a new line.
def mark_newlines!
- value.accept(Newlines.new(Array.new(1 + source.offsets.size, false)))
end
end
end
@@ -69,7 +69,14 @@ module Prism
# nodes.
def compile
result = Prism.parse("case nil\nin #{query}\nend")
- compile_node(result.value.statements.body.last.conditions.last.pattern)
end
# Scan the given node and all of its children for nodes that match the
@@ -77,13 +84,14 @@ module Prism
# matches the pattern. If no block is given, an enumerator will be returned
# that will yield each node that matches the pattern.
def scan(root)
- return to_enum(__method__, root) unless block_given?
@compiled ||= compile
queue = [root]
while (node = queue.shift)
- yield node if @compiled.call(node)
queue.concat(node.compact_child_nodes)
end
end
@@ -174,7 +182,13 @@ module Prism
preprocessed =
node.elements.to_h do |element|
- [element.key.unescaped.to_sym, compile_node(element.value)]
end
compiled_keywords = ->(other) do
@@ -125,19 +125,14 @@ Gem::Specification.new do |spec|
"sig/manifest.yaml",
"sig/prism.rbs",
"sig/prism/compiler.rbs",
- "sig/prism/debug.rbs",
- "sig/prism/desugar_compiler.rbs",
"sig/prism/diser.rbs",
"sig/prism/dot_visitor.rbs",
"sig/prism/dsl.rbs",
- "sig/prism/lex_compat.rbs",
"sig/prism/mutation_compiler.rbs",
- "sig/prism/node_ext.rbs",
- "sig/prism/node_inspector.rbs",
"sig/prism/node.rbs",
"sig/prism/pack.rbs",
- "sig/prism/parse_result/comments.rbs",
- "sig/prism/parse_result/newlines.rbs",
"sig/prism/pattern.rbs",
"sig/prism/ripper_compat.rbs",
"sig/prism/serialize.rbs",