wirb 0.2.0 → 0.2.1

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,2 +1,6 @@
1
+ == 0.2.1
2
+ * Fix 1.8 Rational after requiring 'mathn'
3
+ * Return of string if tokenizer throws an error
4
+
1
5
  == 0.2.0
2
6
  * Initial release.
@@ -1,5 +1,5 @@
1
1
  module Wirb
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
4
4
 
5
5
  require File.dirname(__FILE__) + '/wirb/colors'
@@ -8,11 +8,12 @@ class << Wirb
8
8
 
9
9
  chars = str.split(//)
10
10
 
11
- @state, @token, i = [], '', 0
11
+ @state, @token, @passed, i = [], '', '', 0
12
12
 
13
13
  # helpers
14
14
  pass_custom_state = lambda{ |kind, *options|
15
15
  yield kind, @token unless @token.empty?
16
+ @passed << @token
16
17
  @state.pop if options.include?(:remove)
17
18
  @token = '' unless options.include?(:keep_token)
18
19
  @repeat = true if options.include?(:repeat)
@@ -20,7 +21,7 @@ class << Wirb
20
21
 
21
22
  pass_state = lambda{ |*options| pass_custom_state[ @state[-1], *options ] }
22
23
 
23
- pass = lambda{ |kind, string| yield kind, string }
24
+ pass = lambda{ |kind, string| @passed << string; yield kind, string }
24
25
 
25
26
  set_state = lambda{ |state| @state[-1] = state }
26
27
 
@@ -174,6 +175,9 @@ class << Wirb
174
175
  when :number
175
176
  if c =~ /[0-9e+.-]/ && !(c == '.' && nc == '.')
176
177
  @token << c
178
+ elsif c == '/' # ruby 1.8 mathn
179
+ pass_state[]
180
+ pass[:rational_separator, '/']
177
181
  else
178
182
  pass_state[:remove, :repeat]
179
183
  end
@@ -189,7 +193,7 @@ class << Wirb
189
193
  case c
190
194
  when '('
191
195
  pass[:open_rational, '(']
192
- when /[0-9e-]/
196
+ when /[0-9-]/
193
197
  push_state[:number, :repeat]
194
198
  when '/', ','
195
199
  pass[:rational_separator, c]
@@ -296,11 +300,14 @@ class << Wirb
296
300
  # raise "unknown state #{@state[-1]} #{@state.inspect}"
297
301
  end
298
302
 
299
- # TODO infinite recursion detection and catch errors?
303
+ # TODO infinite recursion detection
300
304
 
301
305
  # next round :)
302
306
  i += 1 unless @repeat
303
307
  end
308
+ rescue
309
+ # p$!
310
+ pass[:default, str.gsub(/^#{@passed}/, '')]
304
311
  end
305
312
  end
306
313
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
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-27 00:00:00 +01:00
17
+ date: 2011-01-28 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20