clj 0.0.3.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/clj/parser.rb +17 -11
  2. data/lib/clj/types.rb +9 -5
  3. metadata +5 -5
data/lib/clj/parser.rb CHANGED
@@ -42,6 +42,8 @@ class Parser < StringScanner
42
42
 
43
43
  INTEGER = /(-?0|-?[1-9]\d*)/
44
44
 
45
+ BIGNUM = /#{INTEGER}N/
46
+
45
47
  FLOAT = /(-?
46
48
  (?:0|[1-9]\d*)
47
49
  (?:
@@ -51,6 +53,8 @@ class Parser < StringScanner
51
53
  )
52
54
  )/x
53
55
 
56
+ BIGDECIMAL = /#{FLOAT}M/
57
+
54
58
  RATIONAL = /(#{INTEGER}\/#{INTEGER})/
55
59
 
56
60
  REGEXP = /#"((\\.|[^"])+)"/
@@ -113,17 +117,19 @@ class Parser < StringScanner
113
117
 
114
118
  def parse_value
115
119
  case
116
- when scan(RATIONAL) then Rational(self[1])
117
- when scan(FLOAT) then Float(self[1])
118
- when scan(INTEGER) then Integer(self[1])
119
- when scan(REGEXP) then /#{self[1]}/
120
- when scan(INSTANT) then DateTime.rfc3339(self[1])
121
- when scan(STRING) then parse_string
122
- when scan(KEYWORD) then self[1].to_sym
123
- when scan(TRUE) then true
124
- when scan(FALSE) then false
125
- when scan(NIL) then nil
126
- else UNPARSED
120
+ when scan(RATIONAL) then Rational(self[1])
121
+ when scan(BIGDECIMAL) then require 'bigdecimal'; BigDecimal(self[1])
122
+ when scan(FLOAT) then Float(self[1])
123
+ when scan(BIGNUM) then Integer(self[1])
124
+ when scan(INTEGER) then Integer(self[1])
125
+ when scan(REGEXP) then /#{self[1]}/
126
+ when scan(INSTANT) then DateTime.rfc3339(self[1])
127
+ when scan(STRING) then parse_string
128
+ when scan(KEYWORD) then self[1].to_sym
129
+ when scan(TRUE) then true
130
+ when scan(FALSE) then false
131
+ when scan(NIL) then nil
132
+ else UNPARSED
127
133
  end
128
134
  end
129
135
 
data/lib/clj/types.rb CHANGED
@@ -63,11 +63,15 @@ class Time
63
63
  end
64
64
  end
65
65
 
66
- if defined? BigDecimal
67
- class BigDecimal
68
- def to_clj (options = {})
69
- inspect + 'M'
70
- end
66
+ class Bignum < Integer
67
+ def to_clj (options = {})
68
+ to_s + 'N'
69
+ end
70
+ end
71
+
72
+ class BigDecimal < Numeric
73
+ def to_clj (options = {})
74
+ to_s('F') + 'M'
71
75
  end
72
76
  end
73
77
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &8585920 !ruby/object:Gem::Requirement
16
+ requirement: &19567340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *8585920
24
+ version_requirements: *19567340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &8585460 !ruby/object:Gem::Requirement
27
+ requirement: &19564220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *8585460
35
+ version_requirements: *19564220
36
36
  description:
37
37
  email: meh@paranoici.org
38
38
  executables: []