brice 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ddba70d209c217914a89b04cabb534d265361553
4
- data.tar.gz: 301300658dfad33b7bc0c8ec3c476333ba311656
2
+ SHA256:
3
+ metadata.gz: 36999aee54c54f1de81d06593f1038074c2b9726c8201752cb692ba28c33a411
4
+ data.tar.gz: 6dd8b2419fc5e1f0a3192ba5fb3273c1ab9c66f1136d12e27865f4ba0e8104db
5
5
  SHA512:
6
- metadata.gz: b37341fda49b517f99dfe9a4b0c752df4b5e594ccdc8f09c5fcee672bb8fb516918849c6c75a39ab96f809cdeeed477c70ea1003bceeb729005d3afe39ec755f
7
- data.tar.gz: fc851d3cb88d455fa4926722e960aa67a38d532c95dd88f744431319f7dcb210d3a2e99c9e81a915b944cf7799913308ac4b4e650dba0d2a43df5315216d6927
6
+ metadata.gz: 9d00c57bd13955221544ae079b8fe8f62553419544c716f1492fab2a3850fe4d8a5f92716b9ab5adfecc9c37b78c3716d02ad40c5d438d709e3c71a3408c3670
7
+ data.tar.gz: 10ab3f892e919a92a29b32e5c4d2064bb3045ea375adfe74648642dbd35af9c0ac9101a754ec31285ca4aa26a1fc3caa766a0c74b5af3a1b1fa46206b1b21afe
data/ChangeLog CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  = Revision history for brice
4
4
 
5
+ == 0.4.2 [2020-09-17]
6
+
7
+ * Ruby 2.7 compatibility.
8
+
5
9
  == 0.4.1 [2016-03-29]
6
10
 
7
11
  * To mark default packages as optional, use underscore in addition to question
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to brice version 0.4.1
5
+ This documentation refers to brice version 0.4.2
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -75,7 +75,7 @@ Travis CI:: https://travis-ci.org/blackwinter/brice
75
75
 
76
76
  == LICENSE AND COPYRIGHT
77
77
 
78
- Copyright (C) 2008-2016 Jens Wille
78
+ Copyright (C) 2008-2020 Jens Wille
79
79
 
80
80
  brice is free software: you can redistribute it and/or modify it under the
81
81
  terms of the GNU Affero General Public License as published by the Free
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  email: %q{jens.wille@gmail.com},
13
13
  license: %q{AGPL-3.0},
14
14
  homepage: :blackwinter,
15
- dependencies: { nuggets: '~> 1.4' },
15
+ dependencies: { nuggets: '~> 1.6' },
16
16
 
17
17
  required_ruby_version: '>= 1.9.3'
18
18
  }
@@ -48,7 +48,7 @@ module Brice
48
48
 
49
49
  # call-seq:
50
50
  # Brice.init { |config| ... }
51
- # Brice.init(:verbose => true) { |config| ... }
51
+ # Brice.init(verbose: true) { |config| ... }
52
52
  #
53
53
  # Initialize Brice and optionally configure any packages.
54
54
  def init(options = {})
@@ -123,6 +123,10 @@ module Brice
123
123
  opt.is_a?(Hash) && opt.key?(key) ? opt[key] : default
124
124
  end
125
125
 
126
+ def error(obj, met, err)
127
+ warn "Error in #{obj}##{met}: #{err.backtrace.first}: #{err} (#{err.class})"
128
+ end
129
+
126
130
  private
127
131
 
128
132
  # call-seq:
@@ -28,9 +28,9 @@ module Brice
28
28
 
29
29
  # Add colour support to IRb.
30
30
  #
31
- # Set your own colours with <tt>config.colours.opt = { :colours => { ... } }</tt>
31
+ # Set your own colours with <tt>config.colours.opt = { colours: { ... } }</tt>
32
32
  # or modify the default scheme (DEFAULT_COLOURS) with <tt>config.colours.opt =
33
- # { :colours => Brice::Colours::DEFAULT_COLOURS.merge(...) }</tt>.
33
+ # { colours: Brice::Colours::DEFAULT_COLOURS.merge(...) }</tt>.
34
34
 
35
35
  module Colours
36
36
 
@@ -94,6 +94,8 @@ module Brice
94
94
  }
95
95
 
96
96
  def init(opt = {})
97
+ require 'ripper'
98
+
97
99
  enable_irb if Brice.opt(opt, :irb, STDOUT.tty?)
98
100
  enable_pp if Brice.opt(opt, :pp, STDOUT.tty?)
99
101
 
@@ -188,15 +190,11 @@ module Brice
188
190
 
189
191
  # Colourize the results of inspect
190
192
  def colourize(str)
191
- res = ''
192
-
193
- Tokenizer.tokenize(str) { |token, value|
193
+ ''.tap { |res| Tokenizer.tokenize(str.to_s) { |token, value|
194
194
  res << colourize_string(value, colours[token])
195
- }
196
-
197
- res
195
+ } }
198
196
  rescue => err
199
- warn "#{err.backtrace.first}: #{err} (#{err.class})"
197
+ Brice.error(self, __method__, err)
200
198
  str
201
199
  end
202
200
 
@@ -237,144 +235,174 @@ module Brice
237
235
 
238
236
  # Tokenize an inspection string.
239
237
 
240
- module Tokenizer
238
+ class Tokenizer
239
+
240
+ EVENT_MAP = {
241
+ # on_CHAR: :unknown,
242
+ # on___end__: :unknown,
243
+ # on_backref: :unknown,
244
+ # on_backtick: :unknown,
245
+ on_comma: :comma,
246
+ on_comment: :unknown,
247
+ on_const: :class,
248
+ # on_cvar: :unknown,
249
+ # on_embdoc: :unknown,
250
+ # on_embdoc_beg: :unknown,
251
+ # on_embdoc_end: :unknown,
252
+ # on_embexpr_beg: :unknown,
253
+ # on_embexpr_end: :unknown,
254
+ # on_embvar: :unknown,
255
+ on_float: :number,
256
+ # on_gvar: :unknown,
257
+ # on_heredoc_beg: :unknown,
258
+ # on_heredoc_end: :unknown,
259
+ on_ident: :symbol,
260
+ # on_ignored_nl: :unknown,
261
+ on_imaginary: :number,
262
+ on_int: :number,
263
+ # on_ivar: :unknown,
264
+ on_kw: :keyword,
265
+ on_label: :unknown,
266
+ on_lbrace: :open_hash,
267
+ on_lbracket: :open_array,
268
+ on_lparen: :unknown,
269
+ # on_nl: :unknown,
270
+ on_op: :refers,
271
+ on_period: :comma,
272
+ # on_qsymbols_beg: :unknown,
273
+ # on_qwords_beg: :unknown,
274
+ on_rational: :number,
275
+ on_rbrace: :close_hash,
276
+ on_rbracket: :close_array,
277
+ on_regexp_beg: :unknown,
278
+ on_regexp_end: :unknown,
279
+ on_rparen: :unknown,
280
+ on_semicolon: :comma,
281
+ on_sp: :whitespace,
282
+ on_symbeg: :symbol_prefix,
283
+ # on_symbols_beg: :unknown,
284
+ # on_tlambda: :unknown,
285
+ # on_tlambeg: :unknown,
286
+ on_tstring_beg: :open_string,
287
+ on_tstring_content: :string,
288
+ on_tstring_end: :close_string,
289
+ # on_words_beg: :unknown,
290
+ # on_words_sep: :unknown
291
+ }
241
292
 
242
- extend self
293
+ OBJECT_RE = %r{
294
+ \A
295
+ ( \#< )
296
+ ( .+ )
297
+ ( > )
298
+ \z
299
+ }x
300
+
301
+ OBJECT_CLASS_RE = %r{
302
+ \A
303
+ (?: \w | :: )+
304
+ }x
305
+
306
+ OBJECT_ADDR_RE = %r{
307
+ \A
308
+ ( : )
309
+ ( 0x [\hx]+ )
310
+ (?= \s | \z )
311
+ }x
312
+
313
+ IVAR_RE = %r{
314
+ \A
315
+ ( @ )
316
+ ( .+ )
317
+ \z
318
+ }x
319
+
320
+ RANGE_RE = %r{
321
+ \A
322
+ \.+
323
+ \z
324
+ }x
325
+
326
+ def self.tokenize(str, &block)
327
+ new(&block).tokenize(str)
328
+ end
329
+
330
+ def initialize(&block)
331
+ @block = block or raise ArgumentError, 'no block given'
332
+ end
333
+
334
+ attr_reader :block
243
335
 
244
336
  def tokenize(str)
245
- raise ArgumentError, 'no block given' unless block_given?
337
+ return if str.empty?
338
+ return if enc_event(str)
246
339
 
247
- chars = str.split(//)
248
- char = last_char = repeat = nil
249
- states, value, index = [], '', 0
340
+ lex, prev = Ripper.lex(str), nil
250
341
 
251
- reset = lambda { |*args|
252
- states.pop
342
+ len = lex[-1][0][-1] + lex[-1][-1].bytesize
343
+ str, rest = str.byteslice(0, len), str.byteslice(len .. -1)
253
344
 
254
- value = ''
255
- repeat = args.first unless args.empty?
256
- }
345
+ return block[:unknown, rest] if str.empty?
257
346
 
258
- yield_last = lambda { |*args|
259
- yield states.last, value
260
- reset[*args]
347
+ lex.each { |_, event, tok|
348
+ sym_event(event, tok, prev) ||
349
+ obj_event(event, tok) ||
350
+ rng_event(event, tok) ||
351
+ var_event(event, tok) ||
352
+ map_event(event, tok)
353
+
354
+ prev = event
261
355
  }
262
356
 
263
- until index > chars.size
264
- char, repeat = chars[index], false
265
-
266
- case states.last
267
- when nil
268
- case char
269
- when ':' then states << :symbol
270
- when '"' then states << :string
271
- when '#' then states << :object
272
- when /[a-z]/i
273
- states << :keyword
274
- repeat = true
275
- when /[0-9-]/
276
- states << :number
277
- repeat = true
278
- when '{' then yield :open_hash, '{'
279
- when '[' then yield :open_array, '['
280
- when ']' then yield :close_array, ']'
281
- when '}' then yield :close_hash, '}'
282
- when /\s/ then yield :whitespace, char
283
- when ',' then yield :comma, ','
284
- when '>' then yield :refers, '=>' if last_char == '='
285
- when '.' then yield :range, '..' if last_char == '.'
286
- when '=' then nil
287
- else yield :unknown, char if char
288
- end
289
- when :symbol
290
- if char =~ /[a-z0-9_!?]/ # should have =, but that messes up foo=>bar
291
- value << char
292
- else
293
- yield :symbol_prefix, ':'
294
- yield_last[true]
295
- end
296
- when :string
297
- if char == '"'
298
- if last_char == '\\'
299
- value[-1] = char
300
- else
301
- yield :open_string, char
302
- yield_last[]
303
- yield :close_string, char
304
- end
305
- else
306
- value << char
307
- end
308
- when :keyword
309
- if char =~ /[a-z0-9_]/i
310
- value << char
311
- else
312
- states[-1] = :class if value =~ /\A[A-Z]/
313
- yield_last[true]
314
-
315
- value << char if char == '.'
316
- end
317
- when :number
318
- case char
319
- when /[0-9e-]/
320
- value << char
321
- when '.'
322
- if last_char == char
323
- value.chop!
324
-
325
- yield_last[]
326
- yield :range, '..'
327
- else
328
- value << char
329
- end
330
- else
331
- yield_last[true]
332
- end
333
- when :object
334
- case char
335
- when '<'
336
- yield :open_object, '#<'
337
- states << :object_class
338
- when ':'
339
- states << :object_addr
340
- when '@'
341
- states << :object_line
342
- when '>'
343
- yield :close_object, '>'
344
- reset[]
345
- end
346
- when :object_class
347
- if char == ':'
348
- yield_last[true]
349
- else
350
- value << char
351
- end
352
- when :object_addr
353
- case char
354
- when '>'
355
- # ignore
356
- when '@'
357
- yield :object_addr_prefix, ':'
358
- yield_last[true]
359
- else
360
- value << char
361
- end
362
- when :object_line
363
- if char == '>'
364
- yield :object_line_prefix, '@'
365
- yield_last[true]
366
- else
367
- value << char
368
- end
369
- else
370
- raise "unknown state: #{states}"
371
- end
357
+ tokenize(rest)
358
+ end
359
+
360
+ private
361
+
362
+ def enc_event(str) # XXX /\A\s*#.*?coding\s*:\s*./
363
+ object($1, $2, $3) if str =~ OBJECT_RE && str.include?('coding')
364
+ end
372
365
 
373
- unless repeat
374
- index += 1
375
- last_char = char
366
+ def obj_event(event, tok)
367
+ object($1, $2, $3) if event == :on_comment && tok =~ OBJECT_RE
368
+ end
369
+
370
+ def sym_event(event, tok, prev)
371
+ block[:symbol, tok] if event == :on_kw && prev == :on_symbeg
372
+ end
373
+
374
+ def rng_event(event, tok)
375
+ block[:range, tok] if event == :on_op && tok =~ RANGE_RE
376
+ end
377
+
378
+ def var_event(event, tok)
379
+ if event == :on_ivar && tok =~ IVAR_RE
380
+ block[:object_line_prefix, $1]
381
+ block[:keyword, $2]
382
+ end
383
+ end
384
+
385
+ def map_event(event, tok)
386
+ block[EVENT_MAP[event], tok]
387
+ end
388
+
389
+ def object(open, str, close)
390
+ block[:open_object, open]
391
+
392
+ if str.sub!(OBJECT_CLASS_RE, '')
393
+ block[:object_class, $&]
394
+
395
+ if str.sub!(OBJECT_ADDR_RE, '')
396
+ block[:object_addr_prefix, $1]
397
+ block[:object_addr, $2]
398
+
399
+ str = tokenize(str)
376
400
  end
377
401
  end
402
+
403
+ block[:unknown, str] if str
404
+
405
+ block[:close_object, close]
378
406
  end
379
407
 
380
408
  end
@@ -43,11 +43,11 @@ module Brice
43
43
  class History
44
44
 
45
45
  DEFAULTS = {
46
- :path => ENV['IRB_HISTORY_FILE'] || File.join(ENV.user_home, '.irb_history'),
47
- :size => (ENV['IRB_HISTORY_SIZE'] || 1000).to_i,
48
- :perms => File::WRONLY | File::CREAT | File::TRUNC,
49
- :uniq => :reverse,
50
- :merge => true
46
+ path: ENV['IRB_HISTORY_FILE'] || File.join(ENV.user_home, '.irb_history'),
47
+ size: (ENV['IRB_HISTORY_SIZE'] || 1000).to_i,
48
+ perms: File::WRONLY | File::CREAT | File::TRUNC,
49
+ uniq: :reverse,
50
+ merge: true
51
51
  }
52
52
 
53
53
  def self.init(opt = {})
@@ -91,6 +91,8 @@ module Brice
91
91
  end
92
92
 
93
93
  def load_history(history = @history)
94
+ @first_line = nil
95
+
94
96
  return unless File.readable?(@path)
95
97
  read_history { |line| history << line }
96
98
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  brice 'init' => nil do |config|
4
4
 
5
- IRB.conf[:AUTO_INDENT] = true
5
+ IRB.conf[:AUTO_INDENT] = true
6
+ IRB.conf[:ECHO_ON_ASSIGNMENT] = true
7
+ IRB.conf[:USE_MULTILINE] = false
6
8
 
7
9
  end
@@ -17,8 +17,8 @@ brice 'prompt' => nil do |config|
17
17
  alias_method :_brice_original_evaluate, :evaluate
18
18
 
19
19
  # Capture execution time
20
- def evaluate(*a)
21
- @_brice_tms = Benchmark.measure { _brice_original_evaluate(*a) }
20
+ def evaluate(*a, **o)
21
+ @_brice_tms = Benchmark.measure { _brice_original_evaluate(*a, **o) }
22
22
  end
23
23
  end
24
24
  end
@@ -39,17 +39,17 @@ brice 'prompt' => nil do |config|
39
39
  lambda { |rt| "#{rt} => %s\n" } : "=> %s\n"
40
40
 
41
41
  IRB.conf[:PROMPT].update(
42
- :BRICE_SIMPLE => {
43
- :PROMPT_I => ' ',
44
- :PROMPT_S => ' ',
45
- :PROMPT_C => ' ',
46
- :RETURN => prompt_return
42
+ BRICE_SIMPLE: {
43
+ PROMPT_I: ' ',
44
+ PROMPT_S: ' ',
45
+ PROMPT_C: ' ',
46
+ RETURN: prompt_return
47
47
  },
48
- :BRICE_VERBOSE => {
49
- :PROMPT_I => "#{prefix}> ",
50
- :PROMPT_S => "#{prefix}> ",
51
- :PROMPT_C => "#{prefix}> ",
52
- :RETURN => prompt_return
48
+ BRICE_VERBOSE: {
49
+ PROMPT_I: "#{prefix}> ",
50
+ PROMPT_S: "#{prefix}> ",
51
+ PROMPT_C: "#{prefix}> ",
52
+ RETURN: prompt_return
53
53
  }
54
54
  )
55
55
 
@@ -24,10 +24,10 @@ brice 'rails' => nil do |config|
24
24
  IRB.conf[:PROMPT] ||= {}
25
25
 
26
26
  IRB.conf[:PROMPT][:BRICE_RAILS] = {
27
- :PROMPT_I => prompt,
28
- :PROMPT_S => prompt,
29
- :PROMPT_C => prompt,
30
- :RETURN => IRB.conf[:PROMPT][:BRICE_SIMPLE] ?
27
+ PROMPT_I: prompt,
28
+ PROMPT_S: prompt,
29
+ PROMPT_C: prompt,
30
+ RETURN: IRB.conf[:PROMPT][:BRICE_SIMPLE] ?
31
31
  IRB.conf[:PROMPT][:BRICE_SIMPLE][:RETURN] : "=> %s\n"
32
32
  }
33
33
 
@@ -40,7 +40,7 @@ brice 'rails' => nil do |config|
40
40
  Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
41
41
  }
42
42
 
43
- define_irb_method(:logger) { |*args|
43
+ define_irb_method(:logger) { |*args, &block|
44
44
  if args.empty?
45
45
  RAILS_DEFAULT_LOGGER
46
46
  else
@@ -51,7 +51,7 @@ brice 'rails' => nil do |config|
51
51
 
52
52
  if block_given?
53
53
  begin
54
- yield # RDoc: Warning: yield outside of method
54
+ block.call
55
55
  ensure
56
56
  logger.level = previous_level
57
57
  end
@@ -39,8 +39,8 @@ module Brice
39
39
 
40
40
  # Convenient shortcut methods.
41
41
  #
42
- # Set <tt>config.shortcuts.opt = { :object => false }</tt> to disable
43
- # ObjectShortcuts, or <tt>config.shortcuts.opt = { :ri => false }</tt>
42
+ # Set <tt>config.shortcuts.opt = { object: false }</tt> to disable
43
+ # ObjectShortcuts, or <tt>config.shortcuts.opt = { ri: false }</tt>
44
44
  # to disable #ri shortcuts.
45
45
 
46
46
  module Shortcuts
@@ -4,7 +4,7 @@ module Brice
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 4
7
- TINY = 1
7
+ TINY = 2
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nuggets
@@ -16,34 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: '1.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
26
+ version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hen
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.8'
33
+ version: '0.9'
34
34
  - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.8.3
36
+ version: 0.9.1
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: '0.8'
43
+ version: '0.9'
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 0.8.3
46
+ version: 0.9.1
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +96,7 @@ files:
96
96
  - lib/brice/rc/010_added_methods_.rb
97
97
  - lib/brice/rc/020_libs.rb
98
98
  - lib/brice/rc/030_history.rb
99
- - lib/brice/rc/040_colours.rb
99
+ - lib/brice/rc/040_colours_.rb
100
100
  - lib/brice/rc/050_shortcuts.rb
101
101
  - lib/brice/rc/060_init.rb
102
102
  - lib/brice/rc/070_prompt.rb
@@ -113,15 +113,13 @@ licenses:
113
113
  metadata: {}
114
114
  post_install_message: |2+
115
115
 
116
- brice-0.4.1 [2016-03-29]:
116
+ brice-0.4.2 [2020-09-17]:
117
117
 
118
- * To mark default packages as optional, use underscore in addition to question
119
- mark, since the latter is not supported on Windows file systems (issue #10
120
- by Hovis Biddle).
118
+ * Ruby 2.7 compatibility.
121
119
 
122
120
  rdoc_options:
123
121
  - "--title"
124
- - brice Application documentation (v0.4.1)
122
+ - brice Application documentation (v0.4.2)
125
123
  - "--charset"
126
124
  - UTF-8
127
125
  - "--line-numbers"
@@ -141,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
139
  - !ruby/object:Gem::Version
142
140
  version: '0'
143
141
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.6.2
142
+ rubygems_version: 3.1.2
146
143
  signing_key:
147
144
  specification_version: 4
148
145
  summary: Extra cool IRb goodness for the masses