diff options
| author | Gopal Patel <gopal@qualified.com> | 2024-02-22 10:38:22 -0800 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-02-24 03:39:28 +0000 |
| commit | aa8841405bd48ac61b3c1397dd864ed2db3b3b2a (patch) | |
| tree | 275bab5f89f328ca744e4340474562f8d642b1c5 | |
| parent | dfee03374632f4da40587cf62858b92da5022a9a (diff) | |
[ruby/prism] Less code modifications. More steep:ignore for now
https://github.com/ruby/prism/commit/7905bdbf83
| -rw-r--r-- | lib/prism/parse_result.rb | 31 | ||||
| -rw-r--r-- | lib/prism/pattern.rb | 5 | ||||
| -rw-r--r-- | prism/templates/lib/prism/dsl.rb.erb | 2 |
3 files changed, 15 insertions, 23 deletions
diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb index 9771da5314..af4006d683 100644 --- a/lib/prism/parse_result.rb +++ b/lib/prism/parse_result.rb @@ -168,13 +168,13 @@ module Prism # The source code that this location represents. def slice - source!.slice(start_offset, length) + source.slice(start_offset, length) end # The character offset from the beginning of the source where this location # starts. def start_character_offset - source!.character_offset(start_offset) + source.character_offset(start_offset) end # The offset from the start of the file in code units of the given encoding. @@ -190,7 +190,7 @@ module Prism # The character offset from the beginning of the source where this location # ends. def end_character_offset - source!.character_offset(end_offset) + source.character_offset(end_offset) end # The offset from the start of the file in code units of the given encoding. @@ -200,30 +200,30 @@ module Prism # The line number where this location starts. def start_line - source!.line(start_offset) + source.line(start_offset) end # The content of the line where this location starts before this location. def start_line_slice - offset = source!.line_start(start_offset) - source!.slice(offset, start_offset - offset) + offset = source.line_start(start_offset) + source.slice(offset, start_offset - offset) end # The line number where this location ends. def end_line - source!.line(end_offset) + source.line(end_offset) end # The column number in bytes where this location starts from the start of # the line. def start_column - source!.column(start_offset) + source.column(start_offset) end # The column number in characters where this location ends from the start of # the line. def start_character_column - source!.character_column(start_offset) + source.character_column(start_offset) end # The column number in code units of the given encoding where this location @@ -235,13 +235,13 @@ module Prism # The column number in bytes where this location ends from the start of the # line. def end_column - source!.column(end_offset) + source.column(end_offset) end # The column number in characters where this location ends from the start of # the line. def end_character_column - source!.character_column(end_offset) + source.character_column(end_offset) end # The column number in code units of the given encoding where this location @@ -281,14 +281,7 @@ module Prism # the beginning of the file. Useful for when you want a location object but # do not care where it points. def self.null - new(nil, 0, 0) - end - - private - - # Access the associated source, raising if not present. - def source! - source or raise "Missing source" + new(nil, 0, 0) # steep:ignore end end diff --git a/lib/prism/pattern.rb b/lib/prism/pattern.rb index 57b30fe678..e12cfd597f 100644 --- a/lib/prism/pattern.rb +++ b/lib/prism/pattern.rb @@ -84,7 +84,7 @@ 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__ || raise, root) unless block_given? + return to_enum(:scan, root) unless block_given? @compiled ||= compile queue = [root] @@ -182,8 +182,7 @@ module Prism preprocessed = node.elements.to_h do |element| key = element.key - if key.respond_to?(:unescaped) - # @type var key: SymbolNode + if key.is_a?(SymbolNode) [key.unescaped.to_sym, compile_node(element.value)] else raise CompilationError, element.inspect diff --git a/prism/templates/lib/prism/dsl.rb.erb b/prism/templates/lib/prism/dsl.rb.erb index 7c55fb10bc..8dbb540952 100644 --- a/prism/templates/lib/prism/dsl.rb.erb +++ b/prism/templates/lib/prism/dsl.rb.erb @@ -36,7 +36,7 @@ module Prism # Create a new Location object def Location(source = nil, start_offset = 0, length = 0) - Location.new(source, start_offset, length) + Location.new(source, start_offset, length) # steep:ignore end <%- nodes.each do |node| -%> |
