pry-doc 0.13.2pre7 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a92e58a3ca468b0210dcebc21c7a7a466ab8167c0fff8b6ef78f634c0d938db
4
- data.tar.gz: 416ea1f86b706da35c66bcb2e4e4b20969d0533abca761ecc9d71e6829124a46
3
+ metadata.gz: 103e744238b577ba5dd9be3e6f68d968d0a5d8389f0e644bcd47097db94615d3
4
+ data.tar.gz: 8a3648f1a0fc7cb95d681dc9d1b4448c9e368c2e51aae18b1c93b3f22f67b557
5
5
  SHA512:
6
- metadata.gz: 68ccf8ee9fd41abda6ed98013335f71cc4bb2e7dad1909fc5c31301e462e2fef2d62b5e8589cf5efa287f05b21e02038bdc186218f738a16f78781fe287d3028
7
- data.tar.gz: a958ebf650666981c40ab95626c6316ef70290193c2d07bd482abafa903b87df0452a246f7561b2fbf43d5d90e40dfae6970fc89d570a171a7507accb304dc2c
6
+ metadata.gz: 8600e1cc9e840f0b1e5506fd034dd9a176f89a854fd002da8f3e8dd9747742a31f7662ef16ecb2d4cfbbeb702b284749c9b14e2e1a08571fa3075fb3233e8531
7
+ data.tar.gz: '063338b70acd7313ce718f1314968aed4cc39e3e7f696803cac63a72db322898b19aecb4945a5dd48039ee27676c471f92ffbb5e8dd096c69c2e48c2659310eb'
@@ -8,72 +8,76 @@
8
8
  # First line is the name of the file
9
9
  # Following lines are the symbols followed by line number with char 127 as separator.
10
10
  module Pry::CInternals
11
- class CFile
12
- SourceLocation = Struct.new(:file, :line, :symbol_type)
11
+ class ETagParser
12
+ class CFile
13
+ # Used to separate symbol from line number
14
+ SYMBOL_SEPARATOR = "\x7f"
15
+ ALTERNATIVE_SEPARATOR = "\x1"
13
16
 
14
- # Used to separate symbol from line number
15
- SYMBOL_SEPARATOR = "\x7f"
16
- ALTERNATIVE_SEPARATOR = "\x1"
17
+ attr_accessor :file_name
18
+ attr_reader :ruby_source_folder
17
19
 
18
- attr_accessor :symbols, :file_name
19
- attr_reader :ruby_source_folder
20
-
21
- def initialize(str, ruby_source_folder: nil)
22
- @ruby_source_folder = ruby_source_folder
23
- @lines = str.lines
24
- @file_name = @lines.shift.split(",").first
25
- end
20
+ def initialize(file_name: file_name, content: content, ruby_source_folder: nil)
21
+ @ruby_source_folder = ruby_source_folder
22
+ @content = content
23
+ @file_name = file_name
24
+ end
26
25
 
27
- def process_symbols
28
- @symbols = @lines.each_with_object({}) do |v, h|
29
- sep = v.include?(ALTERNATIVE_SEPARATOR) ? ALTERNATIVE_SEPARATOR : SYMBOL_SEPARATOR
30
- symbol, line_number = v.split(sep)
31
- next if symbol.strip =~ /^\w+$/ # these symbols are usually errors in etags
32
- h[cleanup_symbol(symbol)] = [source_location_for(symbol, line_number)]
26
+ # Convert a C file to a map of symbols => SourceLocation that are found in that file
27
+ # e.g
28
+ # { "foo" => [SourceLocation], "bar" => [SourceLocation] }
29
+ def symbol_map
30
+ return @symbol_map if @symbol_map
31
+ @symbol_map = @content.each_with_object({}) do |v, h|
32
+ sep = v.include?(ALTERNATIVE_SEPARATOR) ? ALTERNATIVE_SEPARATOR : SYMBOL_SEPARATOR
33
+ symbol, line_number = v.split(sep)
34
+ next if symbol.strip =~ /^\w+$/ # these symbols are usually errors in etags
35
+ h[cleanup_symbol(symbol)] = [source_location_for(symbol, line_number)]
36
+ end
33
37
  end
34
- end
35
38
 
36
- private
39
+ private
37
40
 
38
- def source_location_for(symbol, line_number)
39
- SourceLocation.new(full_path_for(@file_name),
40
- cleanup_linenumber(line_number), symbol_type_for(symbol.strip))
41
- end
41
+ def source_location_for(symbol, line_number)
42
+ SourceLocation.new(full_path_for(@file_name),
43
+ cleanup_linenumber(line_number), symbol_type_for(symbol.strip))
44
+ end
42
45
 
43
- def full_path_for(file_name)
44
- if Pry::Platform.windows?
45
- # windows etags already has the path expanded, wtf
46
- file_name
47
- else
48
- File.join(ruby_source_folder, @file_name)
46
+ def full_path_for(file_name)
47
+ if Pry::Platform.windows?
48
+ # windows etags already has the path expanded, wtf
49
+ file_name
50
+ else
51
+ File.join(ruby_source_folder, @file_name)
52
+ end
49
53
  end
50
- end
51
54
 
52
- def symbol_type_for(symbol)
53
- if symbol =~ /#\s*define/
54
- :macro
55
- elsif symbol =~ /\bstruct\b/
56
- :struct
57
- elsif symbol =~ /\benum\b/
58
- :enum
59
- elsif symbol.start_with?("}")
60
- :typedef_struct
61
- elsif symbol =~/^typedef.*;$/
62
- :typedef_oneliner
63
- elsif symbol =~ /\($/
64
- :function
65
- else
66
- :unknown
55
+ def symbol_type_for(symbol)
56
+ if symbol =~ /#\s*define/
57
+ :macro
58
+ elsif symbol =~ /\bstruct\b/
59
+ :struct
60
+ elsif symbol =~ /\benum\b/
61
+ :enum
62
+ elsif symbol.start_with?("}")
63
+ :typedef_struct
64
+ elsif symbol =~/^typedef.*;$/
65
+ :typedef_oneliner
66
+ elsif symbol =~ /\($/
67
+ :function
68
+ else
69
+ :unknown
70
+ end
67
71
  end
68
- end
69
72
 
70
- def cleanup_symbol(symbol)
71
- symbol = symbol.split.last
72
- symbol.gsub(/\W/, '')
73
- end
73
+ def cleanup_symbol(symbol)
74
+ symbol = symbol.split.last
75
+ symbol.gsub(/\W/, '')
76
+ end
74
77
 
75
- def cleanup_linenumber(line_number)
76
- line_number.split.first.to_i
78
+ def cleanup_linenumber(line_number)
79
+ line_number.split.first.to_i
80
+ end
77
81
  end
78
82
  end
79
83
  end
@@ -1,6 +1,6 @@
1
1
  require 'fileutils'
2
- require_relative 'c_file'
3
2
  require_relative 'symbol_extractor'
3
+ require_relative 'etag_parser'
4
4
  require_relative 'ruby_source_installer'
5
5
 
6
6
  module Pry::CInternals
@@ -10,6 +10,7 @@ module Pry::CInternals
10
10
  class << self
11
11
  attr_accessor :ruby_source_folder
12
12
  attr_accessor :ruby_source_installer
13
+ attr_accessor :symbol_map
13
14
  end
14
15
 
15
16
  # The Ruby version that corresponds to a downloadable release
@@ -73,26 +74,16 @@ module Pry::CInternals
73
74
  line_number_style == :'base-one' ? 1 : line || 1
74
75
  end
75
76
 
77
+ # Returns a hash that maps C symbols to an array of SourceLocations
78
+ # e.g: symbol_map["VALUE"] #=> [SourceLocation_1, SourceLocation_2]
79
+ # A SourceLocation is defined like this: Struct.new(:file, :line, :symbol_type)
80
+ # e.g file: "foo.c", line: 20, symbol_type: "function"
76
81
  def self.symbol_map
77
- @symbol_map ||= (
78
- parse_tagfile
79
- @c_files.each_with_object({}) do |v, h|
80
- h.merge!(v.symbols) { |k, old_val, new_val| old_val + new_val }
81
- end)
82
- end
82
+ return @symbol_map if @symbol_map
83
83
 
84
- def self.parse_tagfile
85
- @c_files ||= tagfile.split("\f\n")[1..-1].map do |v|
86
- CFile.new(v, ruby_source_folder: ruby_source_folder).tap(&:process_symbols)
87
- end
88
- end
89
-
90
- def self.tagfile
91
- tags = File.join(ruby_source_folder, "TAGS")
92
- if !File.exists?(tags)
93
- ruby_source_installer.install
94
- end
95
- @tagfile ||= File.read(tags)
84
+ tags_path = File.join(ruby_source_folder, "TAGS")
85
+ ruby_source_installer.install unless File.exists?(tags_path)
86
+ @symbol_map = ETagParser.symbol_map_for(tags_path, ruby_source_folder)
96
87
  end
97
88
  end
98
89
  end
@@ -0,0 +1,58 @@
1
+ require_relative 'c_file'
2
+
3
+ module Pry::CInternals
4
+ class ETagParser
5
+ SourceLocation = Struct.new(:file, :line, :symbol_type)
6
+
7
+ attr_reader :tags_path
8
+ attr_reader :ruby_source_folder
9
+
10
+ def self.symbol_map_for(tags_path, ruby_source_folder)
11
+ new(tags_path, ruby_source_folder).symbol_map
12
+ end
13
+
14
+ def initialize(tags_path, ruby_source_folder)
15
+ @tags_path = tags_path
16
+ @ruby_source_folder = ruby_source_folder
17
+ end
18
+
19
+ def symbol_map
20
+ parse_tagfile.each_with_object({}) do |c_file, hash|
21
+ # Append all the SourceLocations for a symbol to the same array
22
+ # e.g
23
+ # { "foo" => [SourceLocation_1] }
24
+ # { "foo" => [SourceLocation_2] }
25
+ # => { "foo" => [SourceLocation_1, SourceLocation_2] }
26
+ hash.merge!(c_file.symbol_map) { |key, old_val, new_val| old_val + new_val }
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # \f\n indicates a new C file boundary in the etags file.
33
+ # The first line is the name of the C file, e.g foo.c
34
+ # The successive lines contain information about the symbols for that file.
35
+ def parse_tagfile
36
+ tagfile_sections = tagfile.split("\f\n")
37
+ tagfile_sections.shift # first section is blank
38
+
39
+ tagfile_sections.map do |c_file_section|
40
+ file_name, content = file_name_and_content_for(c_file_section)
41
+ CFile.new(file_name: file_name, content: content, ruby_source_folder: ruby_source_folder)
42
+ end
43
+ end
44
+
45
+ def file_name_and_content_for(c_file_section)
46
+ file_name, *content = c_file_section.lines
47
+ [clean_file_name(file_name), content]
48
+ end
49
+
50
+ def tagfile
51
+ File.read(tags_path)
52
+ end
53
+
54
+ def clean_file_name(file_name)
55
+ file_name.split(",").first
56
+ end
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module PryDoc
2
- VERSION = '0.13.2pre7'
2
+ VERSION = '0.13.2'
3
3
  end
@@ -18,6 +18,7 @@ RSpec.describe PryDoc do
18
18
  end
19
19
 
20
20
  before do
21
+ described_class.symbol_map = nil
21
22
  described_class.ruby_source_folder = File.join(File.dirname(__FILE__), "fixtures/c_source")
22
23
  end
23
24
 
@@ -27,9 +28,9 @@ RSpec.describe PryDoc do
27
28
  expect(described_class.ruby_source_installer).to receive(:install)
28
29
 
29
30
  # will try to read from the 'created' tags file, this will error, so rescue
30
- # (since we're stubbing out `install_and_setup_ruby_source` no tags file
31
+ # (since we're stubbing out `install` no tags file
31
32
  # ever gets created)
32
- described_class.tagfile rescue nil
33
+ described_class.symbol_map rescue nil
33
34
  end
34
35
  end
35
36
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2pre7
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair (banisterfiend)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-24 00:00:00.000000000 Z
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -131,6 +131,7 @@ files:
131
131
  - lib/pry-doc/pry_ext/show_source_with_c_internals.rb
132
132
  - lib/pry-doc/pry_ext/show_source_with_c_internals/c_file.rb
133
133
  - lib/pry-doc/pry_ext/show_source_with_c_internals/code_fetcher.rb
134
+ - lib/pry-doc/pry_ext/show_source_with_c_internals/etag_parser.rb
134
135
  - lib/pry-doc/pry_ext/show_source_with_c_internals/ruby_source_installer.rb
135
136
  - lib/pry-doc/pry_ext/show_source_with_c_internals/symbol_extractor.rb
136
137
  - lib/pry-doc/version.rb
@@ -162,9 +163,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
163
  version: '2.0'
163
164
  required_rubygems_version: !ruby/object:Gem::Requirement
164
165
  requirements:
165
- - - ">"
166
+ - - ">="
166
167
  - !ruby/object:Gem::Version
167
- version: 1.3.1
168
+ version: '0'
168
169
  requirements: []
169
170
  rubyforge_project:
170
171
  rubygems_version: 2.7.3