Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for some missing number literals

  • Loading branch information...
commit 4efe72b47ee843ac0e48f77a37d916e9a5246e46 1 parent f538f5a
@meh authored
Showing with 9 additions and 1 deletion.
  1. +5 −1 lib/clj/parser.rb
  2. +4 −0 test/clj_spec.rb
View
6 lib/clj/parser.rb
@@ -125,7 +125,11 @@ def read_number (ch)
if piece.include? '/'
Rational(piece)
- elsif piece.include? '.' or piece.end_with? 'M'
+ elsif piece.include? 'r'
+ base, number = piece.split('r', 2)
+
+ number.to_i(base.to_i)
+ elsif piece.include? '.' or piece.include? 'e' or piece.end_with? 'M'
if piece.end_with? 'M'
piece[-1] = ''
View
4 test/clj_spec.rb
@@ -122,10 +122,14 @@
it 'parses correctly integers' do
Clojure.parse('2').should == 2
Clojure.parse('1337').should == 1337
+
+ Clojure.parse('16rFF').should == 255
+ Clojure.parse('2r11').should == 3
end
it 'parses correctly floats' do
Clojure.parse('2.3').should == 2.3
+ Clojure.parse('2e3').should == 2000
end
it 'parses correctly rationals' do
Please sign in to comment.
Something went wrong with that request. Please try again.