wirb 2.2.2 → 3.0.0
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 +4 -4
- data/CHANGELOG.md +9 -1
- data/COPYING.txt +1 -1
- data/README.md +9 -15
- data/Rakefile +8 -0
- data/lib/wirb/schema_builder.rb +2 -2
- data/lib/wirb/tokenizer.rb +48 -24
- data/lib/wirb/version.rb +1 -1
- data/spec/spec_helper.rb +18 -0
- data/spec/tokenizer_enumerator_spec.rb +151 -613
- data/spec/tokenizer_hash_spec.rb +136 -12
- data/spec/tokenizer_misc_spec.rb +7 -69
- data/spec/tokenizer_nested_spec.rb +22 -8
- data/spec/tokenizer_number_spec.rb +0 -2
- data/spec/tokenizer_object_spec.rb +30 -59
- data/spec/tokenizer_set_spec.rb +65 -44
- data/spec/tokenizer_symbol_spec.rb +123 -57
- data/wirb.gemspec +15 -8
- metadata +103 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3bad0568e8c6cdae110f6c5c0bb966199fcb8e0b07a70661798f70b935eb2aa9
|
|
4
|
+
data.tar.gz: b18ff8d1e52c62b9b98bc4dd6711c04854ffa0035623ca1fd97edb61ddd3cd99
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 280a3023dbcc80524f36a56099518697cbba22c7f004b038610e506ed0ad19798992eb063f1c71952124d9b35be9fdeec9b6ed17a00f891361615c53312739e2
|
|
7
|
+
data.tar.gz: 70a538972df7321bd79d88366217e48f9ba4175b35e70fef45d8fb65ba2f116b018991449038d920cca026add3039a4deaa5098ed27da040594f68b9ed3cd3a8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
## 3.0.0
|
|
4
|
+
* Require Ruby 3
|
|
5
|
+
* Relax Ruby version requirement to allow Ruby 4.0
|
|
6
|
+
* Support Ruby 3.4 hash inspects
|
|
7
|
+
* Support Ruby 4.0 concise set syntax
|
|
8
|
+
|
|
1
9
|
## 2.2.2
|
|
2
10
|
* Relax Ruby version requirement to allow 3.0
|
|
3
11
|
|
|
@@ -95,7 +103,7 @@
|
|
|
95
103
|
* Fix stupid rescue bug (no more wirb crashes)
|
|
96
104
|
|
|
97
105
|
## 0.2.3 / 0.2.4
|
|
98
|
-
* Support for rubygems-test
|
|
106
|
+
* Support for rubygems-test
|
|
99
107
|
|
|
100
108
|
## 0.2.2
|
|
101
109
|
* Always return inspected string (even when errors happen) and endless-loop
|
data/COPYING.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
## WIRB Interactive Ruby [](https://badge.fury.io/rb/wirb) [<img src="https://github.com/janlelis/wirb/workflows/Test/badge.svg" />](https://github.com/janlelis/wirb/actions?query=workflow%3ATest)
|
|
2
2
|
|
|
3
|
-
The **WIRB** gem syntax
|
|
3
|
+
The **WIRB** gem adds syntax highlighting to inspected Ruby objects. It covers core Ruby classes/modules and most of standard library. Works best as your default REPL inspector, but also works without IRB.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Supports Ruby 3.x and 4.0.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Ancient Rubies (1.9, 1.8): Please use [WIRB 1.0](https://github.com/janlelis/wirb/tree/1.0.3)
|
|
7
|
+
Please note that WIRB also works well for Ruby 1 and Ruby 2 - just install the latest WIRB version possible to install.
|
|
10
8
|
|
|
11
9
|
## Features
|
|
12
10
|
|
|
13
11
|
* Syntax highlighting for inspected Ruby objects
|
|
14
|
-
* No monkey patches anywhere
|
|
15
12
|
* Support for generic objects, especially enumerators, and nested generic objects
|
|
16
|
-
* Supports common standard library objects
|
|
13
|
+
* Supports common standard library objects
|
|
17
14
|
* Color schemas customizable via YAML
|
|
18
15
|
|
|
19
16
|
## Install
|
|
@@ -37,15 +34,17 @@ To activate WIRB permanently, you can add this to the `~/.irbrc` file:
|
|
|
37
34
|
require 'wirb'
|
|
38
35
|
Wirb.start
|
|
39
36
|
|
|
40
|
-
Another way would be to use [Irbtools](https://
|
|
37
|
+
Another way would be to use [Irbtools](https://github.com/janlelis/irbtools), which activates WIRB automatically.
|
|
41
38
|
|
|
42
39
|
## `Kernel#wp`
|
|
43
40
|
|
|
44
|
-
WIRB comes with a pretty printing utility
|
|
41
|
+
WIRB comes with a pretty printing utility:
|
|
45
42
|
|
|
46
43
|
require 'wirb/wp'
|
|
47
44
|
wp some_object
|
|
48
45
|
|
|
46
|
+
Other than similar tools like *pp* or *awesome_print*, it will not change the format the highlighted objects by adding whitespace, but only adds colors.
|
|
47
|
+
|
|
49
48
|
### Bundled Schemas
|
|
50
49
|
|
|
51
50
|
These are the bundled color schemas. You can load one with `Wirb.load_schema(:name)`
|
|
@@ -54,20 +53,15 @@ These are the bundled color schemas. You can load one with `Wirb.load_schema(:na
|
|
|
54
53
|
* `:colorless` (only uses :bright, :underline and :inverse effect)
|
|
55
54
|
* `:ultra` (by @venantius, matches the colorscheme from [Ultra](https://github.com/venantius/ultra) over in Clojure-land)
|
|
56
55
|
|
|
57
|
-
### Usage with Rails
|
|
58
|
-
|
|
59
|
-
If you run into problems using WIRB with Rails, try [the solution in this issue](https://github.com/janlelis/wirb/issues/12#issuecomment-249492524).
|
|
60
56
|
|
|
61
57
|
## Also See
|
|
62
58
|
|
|
63
|
-
* Gem that allows you to configure views for specific objects:
|
|
64
|
-
[hirb](https://github.com/cldwalker/hirb)
|
|
65
59
|
* WIRB is part of: [Irbtools](https://github.com/janlelis/irbtools)
|
|
66
60
|
* More about terminal colors: [Paint](https://github.com/janlelis/paint)
|
|
67
61
|
|
|
68
62
|
## Credits
|
|
69
63
|
|
|
70
|
-
Copyright (c) 2011-
|
|
64
|
+
Copyright (c) 2011-2025 Jan Lelis <https://janlelis.com> see COPYING for details.
|
|
71
65
|
|
|
72
66
|
First tokenizer version was based on the [wirble](https://rubygems.org/gems/wirble) gem:
|
|
73
67
|
Copyright (C) 2006-2009 Paul Duncan <pabs@pablotron.org>
|
data/Rakefile
CHANGED
data/lib/wirb/schema_builder.rb
CHANGED
|
@@ -9,12 +9,12 @@ module Wirb
|
|
|
9
9
|
|
|
10
10
|
schema = normalize_schema(schema_yaml)
|
|
11
11
|
schema[:name] = schema_name.to_sym
|
|
12
|
-
schema
|
|
12
|
+
schema.freeze
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def self.resolve_schema_yaml(yaml_path)
|
|
16
16
|
if yaml_path.is_a? Symbol # bundled themes
|
|
17
|
-
datadir =
|
|
17
|
+
datadir = File.expand_path(File.dirname(__FILE__) + "/../../data/wirb/").freeze
|
|
18
18
|
[yaml_path.to_s, YAML.load_file(File.join(datadir, "#{yaml_path}.yml"))]
|
|
19
19
|
else
|
|
20
20
|
[File.basename(yaml_path).gsub(/\.yml$/, ''), YAML.load_file(yaml_path)]
|
data/lib/wirb/tokenizer.rb
CHANGED
|
@@ -58,14 +58,29 @@ module Wirb
|
|
|
58
58
|
case @state[-1]
|
|
59
59
|
when nil, :hash, :array, :enumerator, :set, :variable # default state
|
|
60
60
|
case c
|
|
61
|
-
when '"'
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
when /
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
when '
|
|
68
|
-
|
|
61
|
+
when '"'
|
|
62
|
+
push_state[:string]
|
|
63
|
+
|
|
64
|
+
when '/'
|
|
65
|
+
push_state[:regexp]
|
|
66
|
+
|
|
67
|
+
when '#'
|
|
68
|
+
push_state[:object]
|
|
69
|
+
|
|
70
|
+
when /[A-Z]/
|
|
71
|
+
push_state[:class, :repeat]
|
|
72
|
+
|
|
73
|
+
when /[a-z]/
|
|
74
|
+
push_state[:word, :repeat]
|
|
75
|
+
|
|
76
|
+
when /[0-9-]/
|
|
77
|
+
then push_state[:number, :repeat]
|
|
78
|
+
|
|
79
|
+
when '.'
|
|
80
|
+
push_state[:range, :repeat]
|
|
81
|
+
|
|
82
|
+
when /\=/
|
|
83
|
+
push_state[:equal, :repeat]
|
|
69
84
|
|
|
70
85
|
when /\s/
|
|
71
86
|
if get_state[:variable]
|
|
@@ -91,6 +106,7 @@ module Wirb
|
|
|
91
106
|
|
|
92
107
|
when '>'
|
|
93
108
|
pop_state[:repeat]
|
|
109
|
+
|
|
94
110
|
when '('
|
|
95
111
|
peek = chars[i+1..-1].join
|
|
96
112
|
if peek =~ /^-?(?:Infinity|NaN|[0-9.e]+)[+-](?:Infinity|NaN|[0-9.e]+)\*?i\)/
|
|
@@ -144,18 +160,18 @@ module Wirb
|
|
|
144
160
|
end
|
|
145
161
|
|
|
146
162
|
when :class
|
|
147
|
-
|
|
148
|
-
when /[a-z0-9_]/i
|
|
163
|
+
if c =~ /[a-z0-9_]/i
|
|
149
164
|
@token << c
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
165
|
+
elsif c == ":" && get_previous_state[:hash]
|
|
166
|
+
pass_custom_state[:symbol, :remove, :repeat]
|
|
167
|
+
@refers_seen[-1] = true
|
|
168
|
+
elsif @token =~ /^(Infinity|NaN)$/
|
|
169
|
+
set_state[:special_number, :repeat]
|
|
170
|
+
elsif c ==':' && nc == ':'
|
|
171
|
+
pass_state[]
|
|
172
|
+
pass[:class_separator, '::']
|
|
173
|
+
elsif !(c == ':' && lc == ':')
|
|
174
|
+
pass_state[:remove, :repeat]
|
|
159
175
|
end
|
|
160
176
|
|
|
161
177
|
when :symbol
|
|
@@ -192,10 +208,15 @@ module Wirb
|
|
|
192
208
|
end
|
|
193
209
|
|
|
194
210
|
when :string
|
|
195
|
-
if c == '"' && ( !( @token =~ /\\+$/; $& ) || $&.size % 2 == 0 ) # allow escaping of " and
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
211
|
+
if c == '"' && ( !( @token =~ /\\+$/; $& ) || $&.size % 2 == 0 ) # allow escaping of " and work around \\
|
|
212
|
+
if nc == ':' && get_previous_state[:hash]
|
|
213
|
+
set_state[:symbol_string, :repeat]
|
|
214
|
+
@refers_seen[-1] = true
|
|
215
|
+
else
|
|
216
|
+
pass[:open_string, '"']
|
|
217
|
+
pass_state[:remove]
|
|
218
|
+
pass[:close_string, '"']
|
|
219
|
+
end
|
|
199
220
|
else
|
|
200
221
|
@token << c
|
|
201
222
|
end
|
|
@@ -221,6 +242,9 @@ module Wirb
|
|
|
221
242
|
if c =~ /[a-z0-9_]/i
|
|
222
243
|
@token << c
|
|
223
244
|
pass_custom_state[@token.to_sym, :remove] if %w[nil false true].include?(@token)
|
|
245
|
+
elsif c == ":"
|
|
246
|
+
pass_custom_state[:symbol, :remove, :repeat]
|
|
247
|
+
@refers_seen[-1] = true
|
|
224
248
|
else
|
|
225
249
|
pass_state[:remove, :repeat]
|
|
226
250
|
end
|
|
@@ -337,7 +361,7 @@ module Wirb
|
|
|
337
361
|
set_state[@token.to_sym]
|
|
338
362
|
else
|
|
339
363
|
set_state[:object_description]
|
|
340
|
-
if @token == "enumerator"
|
|
364
|
+
if @token == "enumerator"
|
|
341
365
|
push_state[:enumerator]
|
|
342
366
|
end
|
|
343
367
|
end
|
data/lib/wirb/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -2,6 +2,12 @@ require 'wirb'
|
|
|
2
2
|
require 'wirb/wp'
|
|
3
3
|
require 'ruby_engine'
|
|
4
4
|
|
|
5
|
+
# CONFIG
|
|
6
|
+
|
|
7
|
+
RSpec.configure do |config|
|
|
8
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
|
9
|
+
end
|
|
10
|
+
|
|
5
11
|
# TOKENIZER
|
|
6
12
|
|
|
7
13
|
def tokenizer(filename)
|
|
@@ -80,3 +86,15 @@ end
|
|
|
80
86
|
OBJECT_ID = /0x[0-9a-f]+/
|
|
81
87
|
|
|
82
88
|
def ws(obj) puts Wirb::Tokenizer.run(obj.inspect).map{|*x| x.inspect + ','}*$/ end
|
|
89
|
+
|
|
90
|
+
def spaced_hashes?
|
|
91
|
+
RUBY_VERSION >= "3.4.0"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def symbol_hash_keys?
|
|
95
|
+
RUBY_VERSION >= "3.4.0"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def concise_set?
|
|
99
|
+
RUBY_VERSION >= "4.0.0"
|
|
100
|
+
end
|