wirb 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.3.2
2
+ * Improve :<=> parsing :D
3
+ * Support gem requirements (:gem_requirement_condition, :gem_requirement_version) and gem dependencies
4
+
1
5
  == 0.3.1
2
6
  * Fix ;$., ;$", :$,
3
7
 
data/README.rdoc CHANGED
@@ -1,6 +1,8 @@
1
1
  == Wavy Interactive Ruby
2
2
  *Wirb* colorizes your inspected Ruby objects. It is based on Wirble[http://pablotron.org/software/wirble/], but only provides and improves result highlighting.
3
3
 
4
+ http://travis-ci.org/janlelis/wirb.png
5
+
4
6
  == Install
5
7
  Install the gem with:
6
8
 
@@ -13,21 +15,21 @@ Add to your <tt>~/.irbrc</tt>
13
15
  require 'wirb'
14
16
  Wirb.start
15
17
 
16
- == Improvements and fixed Wirble bugs
17
- * Does not change the inspect value (e.g. ranges with 4 instead of 3 dots)
18
- * Basic support for regexes
19
- * Fixes some symbol bugs (e.g. :+, :*, ...)
18
+ == Features
19
+ * Syntax highlighting for Ruby objects
20
+ * Does not change the inspect value
20
21
  * Support for generic objects, especially sets and enumerators
21
22
  * Comes with tests
22
23
  * Can be used without irb
23
- * Supports 1.8, 1.9, jruby, rbx
24
+ * Limited stdlib/gem objects support (e.g. Set, Gem::Requirement)
25
+ * Supports 1.8, 1.9, jruby, rbx, head
24
26
 
25
27
  == Customize
26
28
  The color schema can be changed with:
27
29
 
28
30
  Wirb.schema = { :comma => :purple, ... }
29
31
 
30
- Wirb color schemas are (almost) compatible with those from the original Wirble, but there are many extensions. Take a look at wirb/schema.rb or <tt>Wirb.schema</tt> for a list of available token descriptions. See wirb/colors.rb or <tt>Wirb::COLORS</tt> for the available colors.
32
+ Wirb color schemas are (almost) compatible with those from the original Wirble, but there are lots of extensions. Take a look at wirb/schema.rb or <tt>Wirb.schema</tt> for a list of available token descriptions. See wirb/colors.rb or <tt>Wirb::COLORS</tt> for the available colors.
31
33
 
32
34
  Color schemas wanted! You've got a good looking alternative color schema? Please post it on the wiki[https://github.com/janlelis/wirb/wiki/schemas], it may be bundled with a next version ;)
33
35
 
@@ -38,9 +40,9 @@ You can colorize any object with <tt>wp</tt> (wavy_print):
38
40
  wp some_object, :light_red
39
41
 
40
42
  == Also see
41
- * hirb[https://github.com/cldwalker/hirb]
42
- * irbtools[https://github.com/janlelis/irbtools]
43
- * ripl-color_result[https://github.com/janlelis/ripl-color_result]
43
+ * Configure views for specific objects: hirb[https://github.com/cldwalker/hirb]
44
+ * Wirb is part of: irbtools[https://github.com/janlelis/irbtools]
45
+ * ripl is an irb alternative, syntax highlighting plugin (uses wirb by default): ripl-color_result[https://github.com/janlelis/ripl-color_result]
44
46
 
45
47
  == Credits
46
48
  Copyright (c) 2011 Jan Lelis <http://rbjl.net>, see COPYING for details.
data/lib/wirb/schema.rb CHANGED
@@ -59,11 +59,13 @@ module Wirb
59
59
 
60
60
  # misc
61
61
  :default => nil,
62
- :keyword => nil, # some lowercased word, merge with default?
62
+ :keyword => nil, # some lowercased word
63
63
  :time => :purple,
64
64
  :nil => :light_red,
65
65
  :false => :red,
66
66
  :true => :green,
67
+ :gem_requirement_condition => :cyan,
68
+ :gem_requirement_version => :light_cyan,
67
69
  }
68
70
  end
69
71
 
@@ -1,6 +1,6 @@
1
1
  class << Wirb
2
2
  # This is an extended version of the original wirble tokenizer.
3
- # Almost everyone would say that 300 lines long case statements need refactoring, but
3
+ # Almost everyone would say that 400 lines long case statements need refactoring, but
4
4
  # ...sometimes it just doesn't matter ;)
5
5
  def tokenize(str)
6
6
  raise ArgumentError, 'Tokenizer needs an inspect-string' unless str.is_a? String
@@ -52,7 +52,7 @@ class << Wirb
52
52
  # warn "char = #{c} state = #{@state*':'}"
53
53
 
54
54
  case @state[-1]
55
- when nil, :hash, :array, :enumerator, :set, :variable # "default" state
55
+ when nil, :hash, :array, :enumerator, :set, :variable # default state
56
56
  case c
57
57
  when '"' then push_state[:string]
58
58
  when '/' then push_state[:regexp]
@@ -61,6 +61,7 @@ class << Wirb
61
61
  when /[a-z]/ then push_state[:keyword, :repeat]
62
62
  when /[0-9-]/ then push_state[:number, :repeat]
63
63
  when '.' then push_state[:range, :repeat]
64
+ when /[~=]/ then push_state[:gem_requirement_condition, :repeat]
64
65
 
65
66
  when /\s/
66
67
  if get_state[:variable]
@@ -74,6 +75,7 @@ class << Wirb
74
75
  pop_state[:repeat]
75
76
  else
76
77
  pass[:comma, ',']
78
+ @refers_seen[-1] = false if get_state[:hash]
77
79
  end
78
80
 
79
81
  when ':'
@@ -84,14 +86,10 @@ class << Wirb
84
86
  end
85
87
 
86
88
  when '>'
87
- if lc == '='
88
- if get_state[:hash]
89
- pass[:refers, '=>']
90
- else # MAYBE remove this <=> cheat
91
- pass[:symbol, '=>']
92
- end
93
- elsif get_state[:variable]
89
+ if get_state[:variable]
94
90
  pop_state[:repeat]
91
+ elsif @token == '' && nc =~ /[= ]/
92
+ push_state[:gem_requirement_condition, :repeat]
95
93
  end
96
94
  when '('
97
95
  if nc =~ /[0-9-]/
@@ -106,6 +104,8 @@ class << Wirb
106
104
  pass[:open_set, '{']; push_state[nil] # {{ means set-hash
107
105
  else
108
106
  pass[:open_hash, '{']; push_state[:hash]
107
+ @refers_seen ||= []
108
+ @refers_seen.push false
109
109
  end
110
110
 
111
111
  when '['
@@ -121,6 +121,7 @@ class << Wirb
121
121
  when '}'
122
122
  if get_state[:hash]
123
123
  pass[:close_hash, '}']
124
+ @refers_seen.pop
124
125
  elsif get_previous_state[:set]
125
126
  pass[:close_set, '}']
126
127
  pop_state[] # remove extra nil state
@@ -129,9 +130,14 @@ class << Wirb
129
130
  pop_state[] if get_state[:enumerator]
130
131
 
131
132
  when '<'
132
- pass[:open_object, '<']
133
- push_state[:ruby_vm]
134
- push_state[:object_class]
133
+ if nc =~ /[= ]/
134
+ push_state[:gem_requirement_condition, :repeat]
135
+ else # MAYBE slightly refactoring
136
+ pass[:open_object, '<']
137
+ push_state[:object]
138
+ push_state[:object_class]
139
+ open_brackets = 0
140
+ end
135
141
 
136
142
  # else
137
143
  # warn "ignoring char #{c.inspect}" if @debug
@@ -165,7 +171,7 @@ class << Wirb
165
171
  else
166
172
  if c == ']' && lc == '['
167
173
  @token << c
168
- elsif c == '=' && nc != '>' # FIXME: spaceship error
174
+ elsif c == '=' && nc != '>'
169
175
  @token << c
170
176
  elsif c =~ /[.,]/ && lc == '$' && llc == ':'
171
177
  @token << c
@@ -293,24 +299,19 @@ class << Wirb
293
299
  pass_state[]
294
300
  pass[:class_separator, '::']
295
301
  elsif !(c == ':' && lc == ':')
296
- if get_previous_state[:ruby_vm]
297
- pass_state[]
298
- pop_state[:remove]
302
+ pass_state[:keep_token]
303
+ pass[:object_description_prefix, c]
304
+
305
+ @token = @token.downcase
306
+ if %w[set instructionsequence].include?(@token)
307
+ set_state[@token.to_sym]
299
308
  else
300
- pass_state[:keep_token]
301
- pass[:object_description_prefix, c]
302
-
303
- @token = @token.downcase
304
- if %w[set].include?(@token)
305
- set_state[@token.to_sym]
306
- else
307
- set_state[:object_description]
308
- if %w[enumerator].include?(@token) && RUBY_VERSION >= '1.9'
309
- push_state[@token.to_sym]
310
- end
309
+ set_state[:object_description]
310
+ if %w[enumerator].include?(@token) && RUBY_VERSION >= '1.9'
311
+ push_state[@token.to_sym]
311
312
  end
312
- @token = ''
313
313
  end
314
+ @token = ''
314
315
  end
315
316
  end
316
317
 
@@ -374,7 +375,6 @@ class << Wirb
374
375
  push_state[:object_line_number]
375
376
  elsif c == '>' # e.g. RubyVM
376
377
  pass_state[:remove, :repeat]
377
- pass[:close_object, '>'] # TODO move somewhere else if disturbing
378
378
  else
379
379
  @token << c
380
380
  end
@@ -386,12 +386,38 @@ class << Wirb
386
386
  pass_state[:remove, :repeat]
387
387
  end
388
388
 
389
- # <RubyVM::InstructionSequence:pp@/home/jan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/output-method.rb>
390
- when :ruby_vm # TODO write tests
389
+ when :gem_requirement_condition
390
+ if c == '>' && lc == '='
391
+ @token = ''; pop_state[] # TODO in pass helper
392
+ if get_state[:hash]
393
+ if nc == '=' || @refers_seen[-1]
394
+ pass[:symbol, '=>']
395
+ else
396
+ pass[:refers, '=>']
397
+ @refers_seen[-1] = true
398
+ end
399
+ else # MAYBE remove this <=> cheat
400
+ pass[:symbol, '=>']
401
+ end
402
+ elsif c =~ /[^\s]/
403
+ @token << c
404
+ else
405
+ pass_state[:remove]
406
+ pass[:whitespace, c]
407
+ push_state[:gem_requirement_version]
408
+ end
409
+
410
+ when :gem_requirement_version
411
+ if c =~ /[0-9a-z.]/i
412
+ @token << c
413
+ else
414
+ pass_state[:remove, :repeat]
415
+ end
416
+
417
+ when :instructionsequence # RubyVM
391
418
  if c =~ /[^@]/i
392
419
  @token << c
393
420
  else
394
- pass[:object_description_prefix, ':']
395
421
  pass[:object_line_prefix, @token + '@']
396
422
  @token = ''
397
423
  set_state[:object_line]
data/lib/wirb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wirb
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
@@ -0,0 +1,80 @@
1
+ describe tokenizer(__FILE__) do
2
+ after :each do check_value end
3
+
4
+ please do check_inspected "> 3.0.0.beta.4"
5
+ tokens.should == [
6
+ [:gem_requirement_condition, ">"],
7
+ [:whitespace, " "],
8
+ [:gem_requirement_version, "3.0.0.beta.4"],
9
+ ]
10
+ end
11
+
12
+ please do check_inspected "< 3"
13
+ tokens.should == [
14
+ [:gem_requirement_condition, "<"],
15
+ [:whitespace, " "],
16
+ [:gem_requirement_version, "3"],
17
+ ]
18
+ end
19
+
20
+ please do check_inspected "<= 3"
21
+ tokens.should == [
22
+ [:gem_requirement_condition, "<="],
23
+ [:whitespace, " "],
24
+ [:gem_requirement_version, "3"],
25
+ ]
26
+ end
27
+
28
+ please do check_inspected "{1=>>= 0}"
29
+ tokens.should == [
30
+ [:open_hash, '{'],
31
+ [:number, '1'],
32
+ [:refers, '=>'],
33
+ [:gem_requirement_condition, ">="],
34
+ [:whitespace, " "],
35
+ [:gem_requirement_version, "0"],
36
+ [:close_hash, '}'],
37
+ ]
38
+ end
39
+
40
+ if Gem::Specification.respond_to? :find_by_name
41
+ only19 do
42
+ please do
43
+ require 'rspec'
44
+ check [Gem::Specification.find_by_name('rspec').dependencies.first.requirement]*2
45
+ tokens.should == [
46
+ [:open_array, '['],
47
+ [:gem_requirement_condition, "~>"],
48
+ [:whitespace, " "],
49
+ [:gem_requirement_version, RSpec::Version::STRING],
50
+ [:comma, ","],
51
+ [:whitespace, " "],
52
+ [:gem_requirement_condition, "~>"],
53
+ [:whitespace, " "],
54
+ [:gem_requirement_version, RSpec::Version::STRING],
55
+ [:close_array, ']'],
56
+ ]
57
+ end
58
+ end
59
+
60
+ please do
61
+ check Gem::Specification.find_by_name('wirb').dependencies.first
62
+ tokens.should == [ # <Gem::Dependency type=:development name="rspec" requirements=">= 0">
63
+ [:open_object, "<"],
64
+ [:object_class, "Gem"],
65
+ [:class_separator, "::"],
66
+ [:object_class, "Dependency"],
67
+ [:object_description_prefix, " "],
68
+ [:object_description, "type=:development name="],
69
+ [:open_string, "\""],
70
+ [:string, "rspec"],
71
+ [:close_string, "\""],
72
+ [:object_description, " requirements="],
73
+ [:open_string, "\""],
74
+ [:string, ">= 0"],
75
+ [:close_string, "\""],
76
+ [:close_object, ">"],
77
+ ]
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,18 @@
1
+ describe tokenizer(__FILE__) do
2
+ after :each do check_value end
3
+ please do
4
+ check_inspected "<RubyVM::InstructionSequence:pp"\
5
+ "@/home/jan/.rvm/rubies/ruby-1.9.2-p180"\
6
+ "/lib/ruby/1.9.1/irb/output-method.rb>"
7
+ tokens.should == [
8
+ [:open_object, "<"],
9
+ [:object_class, "RubyVM"],
10
+ [:class_separator, "::"],
11
+ [:object_class, "InstructionSequence"],
12
+ [:object_description_prefix, ":"],
13
+ [:object_line_prefix, "pp@"],
14
+ [:object_line, "/home/jan/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/output-method.rb"],
15
+ [:close_object, ">"],
16
+ ]
17
+ end
18
+ end
@@ -37,7 +37,7 @@ describe tokenizer(__FILE__) do
37
37
  [:comma, ","],
38
38
  [:whitespace, " "],
39
39
  [:symbol_prefix, ":"],
40
- # [:symbol, "<=>"], # FIXME
40
+ # [:symbol, "<=>"], # MAYBE fixme
41
41
  [:symbol, "<"],
42
42
  [:symbol, "=>"],
43
43
  [:comma, ","],
@@ -95,7 +95,7 @@ describe tokenizer(__FILE__) do
95
95
  ]
96
96
  end
97
97
 
98
- please do check [[:hallo],{:'hallo'=>:'test'}, {:'hallo='=>:'test='}, {:'<'=>9}]
98
+ please do check [[:hallo],{:'hallo'=>:'test'}, {:'hallo='=>:'test='}, {:'<'=>9}, {:'<=>'=>9}, {:'<'=>:'<=>'}]
99
99
  tokens.should == [
100
100
  [:open_array, "["],
101
101
  [:open_array, "["],
@@ -128,6 +128,27 @@ describe tokenizer(__FILE__) do
128
128
  [:refers, "=>"],
129
129
  [:number, "9"],
130
130
  [:close_hash, "}"],
131
+ [:comma, ","],
132
+ [:whitespace, " "],
133
+ [:open_hash, "{"],
134
+ [:symbol_prefix, ":"],
135
+ # [:symbol, "<=>"], # MAYBE fixme
136
+ [:symbol, "<"],
137
+ [:symbol, "=>"],
138
+ [:refers, "=>"],
139
+ [:number, "9"],
140
+ [:close_hash, "}"],
141
+ [:comma, ","],
142
+ [:whitespace, " "],
143
+ [:open_hash, "{"],
144
+ [:symbol_prefix, ":"],
145
+ [:symbol, "<"],
146
+ [:refers, "=>"],
147
+ [:symbol_prefix, ":"],
148
+ # [:symbol, "<=>"], # MAYBE fixme
149
+ [:symbol, "<"],
150
+ [:symbol, "=>"],
151
+ [:close_hash, "}"],
131
152
  [:close_array, "]"],
132
153
  ]
133
154
  end
data/wirb.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.license = 'MIT'
18
18
  s.add_development_dependency 'rspec'
19
19
  s.add_development_dependency 'rspec-core'
20
+ s.add_development_dependency 'rake'
20
21
  s.add_development_dependency 'zucker', '>= 11'
21
22
 
22
23
  len = s.homepage.size
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: wirb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.1
5
+ version: 0.3.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jan Lelis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-26 00:00:00 Z
13
+ date: 2011-06-15 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -35,16 +35,27 @@ dependencies:
35
35
  type: :development
36
36
  version_requirements: *id002
37
37
  - !ruby/object:Gem::Dependency
38
- name: zucker
38
+ name: rake
39
39
  prerelease: false
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: "11"
45
+ version: "0"
46
46
  type: :development
47
47
  version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: zucker
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "11"
57
+ type: :development
58
+ version_requirements: *id004
48
59
  description: Colorizes your irb results. It's based on Wirble but only provides result highlighting. Just call Wirb.start and enjoy the colors ;).
49
60
  email: mail@janlelis.de
50
61
  executables: []
@@ -76,7 +87,9 @@ files:
76
87
  - spec/tokenizer_object_spec.rb
77
88
  - spec/tokenizer_nested_spec.rb
78
89
  - spec/tokenizer_time_spec.rb
90
+ - spec/tokenizer_rubyvm_spec.rb
79
91
  - spec/tokenizer_string_spec.rb
92
+ - spec/tokenizer_rubygems_spec.rb
80
93
  - COPYING.txt
81
94
  - README.rdoc
82
95
  - CHANGELOG.rdoc