wirb 0.2.1 → 0.2.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.
@@ -1,3 +1,7 @@
1
+ == 0.2.2
2
+ * Always return inspected string (even when errors happen) and endless-loop protection
3
+ * Recognize active record class descriptions
4
+
1
5
  == 0.2.1
2
6
  * Fix 1.8 Rational after requiring 'mathn'
3
7
  * Return of string if tokenizer throws an error
@@ -1,7 +1,4 @@
1
- module Wirb
2
- VERSION = '0.2.1'
3
- end
4
-
1
+ require File.dirname(__FILE__) + '/wirb/version'
5
2
  require File.dirname(__FILE__) + '/wirb/colors'
6
3
  require File.dirname(__FILE__) + '/wirb/schema'
7
4
  require File.dirname(__FILE__) + '/wirb/tokenizer'
@@ -26,10 +23,15 @@ class << Wirb
26
23
  end
27
24
 
28
25
  # Colorize a result string
29
- def colorize_result(str, custom_schema = schema)
30
- tokenize(str).map{ |kind, token|
26
+ def colorize_result(string, custom_schema = schema)
27
+ check = ''
28
+ colorful = tokenize(string).map do |kind, token|
29
+ check << token
31
30
  colorize_string token, custom_schema[kind]
32
- }.join
31
+ end.join
32
+
33
+ # always display the correct inspect string!
34
+ check == string ? colorful : string
33
35
  end
34
36
 
35
37
  # Colorize results in irb/ripl (or whatever might be supported in future)
@@ -8,7 +8,8 @@ class << Wirb
8
8
 
9
9
  chars = str.split(//)
10
10
 
11
- @state, @token, @passed, i = [], '', '', 0
11
+ @state, @token, i = [], '', 0
12
+ @passed, snapshot = '', nil # exception handling
12
13
 
13
14
  # helpers
14
15
  pass_custom_state = lambda{ |kind, *options|
@@ -57,11 +58,17 @@ class << Wirb
57
58
  when /[A-Z]/ then push_state[:class, :repeat]
58
59
  when /[a-z]/ then push_state[:keyword, :repeat]
59
60
  when /[0-9-]/ then push_state[:number, :repeat]
60
- when '(' then push_state[:rational, :repeat]
61
- when '.' then push_state[:range, :repeat]
61
+ when '.' then push_state[:range, :repeat]
62
62
  when /\s/ then pass[:whitespace, c]
63
63
  when ',' then pass[:comma, ',']
64
64
  when '>' then pass[:refers, '=>'] if lc == '='
65
+ when '('
66
+ if nc =~ /[0-9-]/
67
+ push_state[:rational, :repeat]
68
+ else
69
+ push_state[:object_description, :repeat]
70
+ open_brackets = 0 # TODO also count ()?
71
+ end
65
72
 
66
73
  when '{'
67
74
  if get_state[:set]
@@ -300,13 +307,17 @@ class << Wirb
300
307
  # raise "unknown state #{@state[-1]} #{@state.inspect}"
301
308
  end
302
309
 
303
- # TODO infinite recursion detection
304
-
305
310
  # next round :)
306
- i += 1 unless @repeat
311
+ if !@repeat
312
+ i += 1
313
+ elsif snapshot && Marshal.load(snapshot) == [@state, @token, llc, lc, c, nc] # loop protection
314
+ raise 'Wirb Bug :/'
315
+ end
316
+
317
+ snapshot = Marshal.dump([@state, @token, llc, lc, c, nc])
307
318
  end
308
319
  rescue
309
- # p$!
320
+ # p$!, $!.backtrace[0]
310
321
  pass[:default, str.gsub(/^#{@passed}/, '')]
311
322
  end
312
323
  end
@@ -0,0 +1,3 @@
1
+ module Wirb
2
+ VERSION = '0.2.2'
3
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require 'rubygems' unless defined? Gem
3
- require File.dirname(__FILE__) + "/lib/wirb"
3
+ require File.dirname(__FILE__) + "/lib/wirb/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "wirb"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Lelis
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-28 00:00:00 +01:00
17
+ date: 2011-01-29 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -33,6 +33,7 @@ files:
33
33
  - lib/wirb/tokenizer.rb
34
34
  - lib/wirb/wp.rb
35
35
  - lib/wirb/colors.rb
36
+ - lib/wirb/version.rb
36
37
  - lib/wirb/irb.rb
37
38
  - README.rdoc
38
39
  - CHANGELOG.rdoc